0

我目前正在编写一个 Java 脚本,以将一堆书籍从冗长的纯文本文件导入数据库。我已将所有书籍解析为书籍对象,并尝试将它们写入数据库。但是,我在以下字符串上收到一个缺少逗号的异常“ORA-00917:缺少逗号”:

INSERT INTO THE_TABLE VALUES( 'Yes' , '50388,50389' , 'Humanities and Performing Arts' , 'Required' , 'Ember, Carol & Ember, Melvin' , 'Human Culture' , '2nd' , '2012' , 'Pearson' , 'This is for CRN's 4879 & 2486' , '9780205251438' , '50' , 'null' , 'null' , 'null' , 'Spring 2013' , 'ROTN 4270' , 'Required' , 'Ember, Carol & Ember, Melvin,' , 'Human Culture' , 'Pearson,' , '2nd' , 'Edition,' , '2012.' , 'null' , 'Not Applicable' , 'Not Applicable' , 'Not Applicable' , 'Spring 2013' , 'ANTH 270' , '50388,50389' , 'Humanities and Performing Arts' , 'Required' , 'This is for CRN's 15454 & 48456, 'Ember, Carol & Ember, Melvin,' , 'Human Culture' , 'Pearson,' , '2nd' , 'Edition,' , '2012.' , '9780205251438' , '50' , 'null' , 'null' , 'Not Applicable' , 'Not Applicable' , 'Not Applicable' , 'null' , 'null' , 'null' )

我看不到缺少逗号的地方。这个例外还有其他原因吗?

4

3 回答 3

4

错误很明显,您在插入语句中的某处缺少逗号。

但是,我强烈建议您在使用 JDBC 执行 SQL 查询时使用PreparedStatement而不是简单的 Statement 以防止 SQL INJECTION。

String query="Insert into table values(?,?);";
PreparedStatement stmnt = conn.preparedStatement(query);
stmnt.setString(1, "val1");
stmnt.setString(2, "val2");

在此处查看有关如何在 java 中使用preparedstatement

于 2012-12-06T17:12:25.557 回答
2

, 'This is for CRN's 15454 & 48456,

在那里。
请注意在 (48456) 之后您是如何错过滴答声的。可能是因为(CRN)部分。

另外,我建议使用 arecord以方便编程。插入这样的值很麻烦。:) 保持良好的工作。

于 2012-12-06T17:09:26.123 回答
0

'Ember, Carol & Ember, Melvin,'可能是导致问题尝试'Ember, Carol &' || ' Ember, Melvin,'

于 2012-12-06T17:12:04.537 回答