将java应用程序中的float插入到Oracle数据库11gr2中



在将Jtable中的值插入数据库时,我收到以下错误:

:java.sql.SQLSyntaxErrorException:ORA-01722:无有效

以下是主要的依赖项:

String a=(String) (table.getValueAt(j,1));
Float echantillons= Float.parseFloat(a);
int rs=stmt.executeUpdate("insert into testing values ('"+echantillons+"')");
名称为Null?类型-------------------------------------------------------------ECHANTILLIONS数(10,20)

使用参数化SQL。

这不仅是一种通用的良好做法(养成使用它的习惯,就可以避免SQL注入),还意味着可以避免Java和Oracle之间的任何国际化问题。也许您的问题出现了——这两个系统有不同的十进制分隔符(,.)。

String a=(String) (table.getValueAt(j,1));
Float echantillons= Float.parseFloat(a);
PreparedStatement stmt = connection.prepareStatement(
        "insert into testing (echantillions) values (?)");
stmt.setFloat(1, echantillions);
int rs = stmt.executeUpdate();

ORA-01722:无效编号

意味着您正试图在数字字段中插入一个字符串,你有权访问源数据吗?

...'"+echantillons+"'...表示您希望将echantillons的值作为字符串插入。但由于它是NUMBER(10,20),您可能想要:

int rs = stmt.executeUpdate(
             "insert into testing (echantillons) values ("+echantillons+")"); 

参见上文省略的'

最新更新