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

标签 java oracle

我在 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.

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/

相关文章:

Java I/O - 模拟 System.console() 的输入

oracle - float 列上的 oracle 索引对性能有何影响?

oracle - mybatis批量处理多表插入

java - ORA-00933 : SQL command not properly ended on jdbc call

java - 如何使用 ITextRenderer 在每个页面上添加页眉和页脚

java - 将值分配给 String 类而不创建新实例

Java 函数式编程 : creating a map of functions

java - 使用java的内网聊天应用程序

java - 从 PL/SQL 与 Java 处理文本文件

java - 如何批量向oracle sql查询传递参数