我在 HSQL 数据库中有一个表,它有一个标识(整数)列。我想支持使用任意字符串(可能是非数字)对列进行查询。但是,HSQL JDBC 驱动程序尝试将查询参数转换为整数并引发异常。Oracle 驱动程序似乎很好地支持这种情况。
有什么想法可以改变 hsql 驱动程序中的这种行为吗?
org.hsqldb:hsqldb:2.3.0
桌子:
CREATE TABLE some_table(id IDENTITY NOT NULL);
查询:
final String query = "SELECT * FROM some_table WHERE id=?";
String id = "abc";
jdbcTemplate.query(query, new PreparedStatementSetter() {
@Override
public void setValues(PreparedStatement ps) throws SQLException {
ps.setString(1, id);
}
}, someMapper);
例外:
org.springframework.dao.DataIntegrityViolationException: PreparedStatementCallback; SQL [SELECT * FROM some_table WHERE id=?]; data exception: invalid character value for cast; nested exception is java.sql.SQLDataException: data exception: invalid character value for cast
at org.springframework.jdbc.support.SQLExceptionSubclassTranslator.doTranslate(SQLExceptionSubclassTranslator.java:80)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:605)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:639)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:668)
.
.
.
Caused by: java.sql.SQLDataException: data exception: invalid character value for cast
at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
at org.hsqldb.jdbc.JDBCUtil.throwError(Unknown Source)
at org.hsqldb.jdbc.JDBCPreparedStatement.setParameter(Unknown Source)
at org.hsqldb.jdbc.JDBCPreparedStatement.setString(Unknown Source)
at org.apache.commons.dbcp.DelegatingPreparedStatement.setString(DelegatingPreparedStatement.java:135)
at org.apache.commons.dbcp.DelegatingPreparedStatement.setString(DelegatingPreparedStatement.java:135)
at com.stackoverflow.SomeDao$2.setValues(SomeDao.java:39)
at org.springframework.jdbc.core.JdbcTemplate$1.doInPreparedStatement(JdbcTemplate.java:644)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:589)
... 33 more
Caused by: org.hsqldb.HsqlException: data exception: invalid character value for cast
at org.hsqldb.error.Error.error(Unknown Source)
at org.hsqldb.error.Error.error(Unknown Source)
at org.hsqldb.Scanner.convertToNumber(Unknown Source)
at org.hsqldb.types.NumberType.convertToType(Unknown Source)
... 40 more