我有通過執行PreparedStatement插入數據庫表的JDBC代碼。當我在內存中的HSQLDB數據庫上運行代碼時(作爲JUnit測試的一部分),我得到一個SQLFeatureNotSupportedException,唯一的信息是消息「feature not supported」和供應商代碼-1500。我正在做的是將一個基本的插入表格 - 我無法想象這在最新的HSQLDB中是不受支持的。HSQLDB神祕的異常消息:「不支持的功能」
我的代碼:
public Observations saveOrUpdate(final Observations observations)
{
try
{
if (connection == null)
{
connection = getJdbcTemplate().getDataSource().getConnection();
}
// create the prepared statement
String sql = "INSERT INTO " + Observations.TABLE_NAME +
" (OBS_YEAR, WINTER, SPRING, SUMMER, FALL, ANNUAL, DATA_TYPE, CREATED_DATE, UPDATED_DATE, " +
Observations.ID_COLUMN_NAME +
") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
PreparedStatement preparedStatement = connection.prepareStatement(sql);
preparedStatement.setInt(1, observations.getYear());
preparedStatement.setBigDecimal(2, observations.getJan());
preparedStatement.setBigDecimal(3, observations.getFeb());
preparedStatement.setBigDecimal(4, observations.getMar());
preparedStatement.setBigDecimal(5, observations.getApr());
preparedStatement.setBigDecimal(6, observations.getMay());
preparedStatement.setString(7, observations.getDataType().toString());
preparedStatement.setTimestamp(8, new Timestamp(observations.getCreatedDate().getTime()));
preparedStatement.setTimestamp(9, new Timestamp(observations.getUpdatedDate().getTime()));
preparedStatement.setLong(10, observations.getId());
preparedStatement.executeUpdate(sql);
return observations;
}
catch (SQLException ex)
{
throw new RuntimeException(ex);
}
}
任何人都可以提出什麼可能是我應該進一步調查的問題還是別的什麼嗎?在此先感謝您的幫助。
- 詹姆斯
嘗試發佈信息記錄異常,你的HSQLDB的版本(2.0也許),您的Java版本,等我在尋找爲了幫助你。我認爲這是jre和你的hsqldb兼容的問題。 – Aito 2010-09-21 17:27:13
非常感謝Aito。我正在使用HSQLDB 2.0 JAR文件。我將代碼作爲JUnit 4測試的一部分運行。我從使用1.6 JRE的Eclise IDE啓動它。 DataSource是使用Spring進行配置的,我從Spring JdbcTemplate中獲取了連接,該連接已經配置到包含此代碼的DAO類中。 – 2010-09-21 17:58:52