ORA-17059: Fail to convert to internal representation -无法转换为内部表示
当应用报错误:
could not read column value from result set: RATED15_98_; 无法转换为内部表示
(util.JDBCExceptionReporter 71 ) SQL Error: 17059, SQLState: null
(util.JDBCExceptionReporter 72 ) 无法转换为内部表示
这个错误原因是:数据库里的字段类型与Java里映射该字段属性的类型不能对应转换,例如数据库里字段类型为Varchar2,而Java定义的类型为Long;或者数据库里为Number,而Java定义的对应属性类型为String。
This error occurs when an attempt is made to convert a ResultSet's column value to a type for which the driver has no conversion available.
For example, when trying to read a VARCHAR-column as a Java int.
eg:
The query SELECT 'hello' FROM dual will produce a resultset with one column, of type VARCHAR.
The res.getInt(1) statement attempts to retrieve the value of the column as an int, which leads to error 17059.
Note that the Oracle driver can convert from a char-type to an int if the char-type contains the string-representation of a number.
For example, if the query in the example above would have read SELECT '42' FROM dual, the code-fragment would not cause an error, and the value of x would be 42.
Solution: use the appropriate getter of the ResultSet instance - in the example above, replace the line
// connect to the database final Connection conn = DriverManager.getConnection( "jdbc:oracle:thin:@"+cs, user, pw ); Statement stat = conn.createStatement(); ResultSet res = stat.executeQuery("SELECT 'hello' FROM dual"); if(res.next()) { int x = res.getInt(1); } stat.close(); conn.close();
int x = res.getInt(1); with String x = res.getString(1);