java – . Nextval JDBC insertion problem
•
Java
I try to sequence Nextval is inserted into the table as a primary key, and SQL in Java is
sql = "INSERT INTO USER (USER_PK,ACCOUNTNUMBER,FIRSTNAME,LASTNAME,EMAIL ) VALUES (?,?,?)"; ps = conn.prepareStatement(sql); ps.setString(1,"User.nextval"); ps.setString(2,accountNumber); ps.setString(3,firstName); ps.setString(4,lastName); ps.setString(5,email);
However, the error is ora-01722: invalid number
All other areas are correct. I think it's a matter of order. Is this correct?
Solution
The problem is that the first column is a numeric data type, but your prepared statement is submitting a string / varchar data type The statement runs as is, Oracle has no chance to convert. You use nextval to get the sequence value
This is an alternative to Java's Preparedstatement syntax:
sql = "INSERT INTO USER (USER_PK,EMAIL ) VALUES (user.nextval,?)"; ps = conn.prepareStatement(sql); ps.setString(1,accountNumber); ps.setString(2,firstName); ps.setString(3,lastName); ps.setString(4,email);
This assumes that the user is an existing sequence – change to fit
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码