我在 oracle 中有 FP_BIOMETRIC_DATA 表,其主键是 CUST_NO 和 SERIAL_NO 。 Blob 列是 FINGER_DATA 。所以我想在这个表中插入一条记录。代码如下:
public void saveFingerToDatabase(String username , String key , byte[] data)
{
try {
connection = DBConnectionHandler.getConnection();
PreparedStatement stmt = connection.prepareStatement("insert into FP_BIOMETRIC_DATA (CUST_NO,SERIAL_NO,FINGER_DATA,KEY_VALUE) values (?,?,?,?)");
stmt.setInt(1, Integer.parseInt(username));
stmt.setInt(2, 1);
stmt.setBytes(3, data);
stmt.setString(4, key);
stmt.executeUpdate();
connection.commit();
} catch (SQLException ex) {
Logger.getLogger(SaveDataToDatabase.class.getName()).log(Level.SEVERE, null, ex);
}
try {
connection.close();
} catch (SQLException ex) {
Logger.getLogger(SaveDataToDatabase.class.getName()).log(Level.SEVERE, null, ex);
}
}
但是当我运行此代码时,出现以下错误:
java.sql.SQLException: ORA-01722: invalid number
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:288)
at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:743)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:213)
at oracle.jdbc.driver.T4CPreparedStatement.executeForRows(T4CPreparedStatement.java:952)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1160)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3285)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:3368)
at com.Futronic.WorkedEx.SaveDataToDatabase.saveFingerToDatabase(SaveDataToDatabase.java:43)
at com.Futronic.WorkedEx.DbRecord.Save(DbRecord.java:184)
at com.Futronic.WorkedEx.MainForm.OnEnrollmentComplete(MainForm.java:159)
at com.futronic.SDKHelper.FutronicEnrollment.run(FutronicEnrollment.java:234)
at java.lang.Thread.run(Thread.java:745)
我不明白错误在哪里?请帮我 。
最佳答案
错误代码 ORA-01722 表明您正在将字符串值转换为 int,并且 SQL 抛出错误
检查(字符串)键是否声明为 STRING 或 INTEGER
Description
When you encounter an ORA-01722 error, the following error message will appear:
ORA-01722: invalid number
Cause
You executed a SQL statement that tried to convert a string to a number, but it was unsuccessful.
Resolution
The option(s) to resolve this Oracle error are:
Option #1
Only numeric fields or character fields that contain numeric values can be used in arithmetic operations. Make sure that all expressions evaluate to numbers.
Option #2
If you are adding or subtracting from dates, make sure that you added/substracted a numeric value from the date.
关于java - stmt.executeUpdate() 返回 java.sql.SQLException : ORA-01722: invalid number,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43039746/