我有通过执行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