代码之家  ›  专栏  ›  技术社区  ›  James Adams

hsqldb加密异常消息:“不支持功能”

  •  8
  • James Adams  · 技术社区  · 15 年前

    我有JDBC代码,它通过执行PreparedStatement插入到数据库表中。当我在内存中的hsqldb数据库上运行代码(作为JUnit测试的一部分)时,我得到一个sqlFeatureNotSupportedException,唯一的信息是消息“Feature Not Supported”和供应商代码-1500。我要做的是在一个表中进行一次基本的插入——我无法想象这在最新的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);
        }
    }
    

    有人能建议我应该进一步调查的问题是什么吗?事先谢谢你的帮助。

    ——杰姆斯

    3 回复  |  直到 15 年前
        1
  •  10
  •   Thomas Mueller    15 年前

    你需要打电话 preparedStatement.executeUpdate() (没有参数 sql )

    你调用了方法 PreparedStatement.executeUpdate(String sql) ,根据JDBC规范,这是非法的。再次传递SQL语句实际上没有意义,因为您在创建PreparedStatement对象时已经传递了它。即使认为您传递的是相同的字符串,调用此方法也是不合法的。奇怪的是,调用一个方法是不合法的:—),但事实就是这样。在这种情况下,所有符合标准的JDBC驱动程序都需要抛出一个异常。

    但我同意错误信息是神秘的。

        2
  •  1
  •   James Adams    15 年前

    我在中发现的一些进一步的信息 http://hsqldb.org/doc/changelog_1_7_2.txt :

    The execute(String sql), executeUpdate(String sql) and executeQuery(String sql) 
    commands are no-longer supported for PreparedStatements according to JDBC specs. 
    Use an ordinary Statement for calling these methods.
    
        3
  •  -1
  •   Drew Wills    15 年前

    hsqldb的系统性问题通常是由于服务器版本与驱动程序版本不匹配(根据我的经验,任何不匹配都不会起作用)。

    我主要怀疑这个 不是 你的问题。既然您说数据库“在内存中”,我猜服务器和驱动程序是相同的.jar文件。但如果我猜错了,我想我会把这个扔出去。