gpt4 book ai didi

java - stmt.executeUpdate() 返回 java.sql.SQLException : ORA-01722: invalid number

转载 作者:行者123 更新时间:2023-11-30 06:49:18 25 4
gpt4 key购买 nike

我在 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) 键是否声明为 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.

https://www.techonthenet.com/oracle/errors/ora01722.php

关于java - stmt.executeUpdate() 返回 java.sql.SQLException : ORA-01722: invalid number,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43039746/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com