我目前正在编写一个 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' )
我看不出哪里缺少逗号。是否还有其他原因导致此异常?
最佳答案
错误很明显,您在插入语句中的某处缺少逗号。
但是,我强烈建议您使用 PreparedStatement使用 JDBC 执行 SQL 查询时,不要使用简单的 Statement,以防止 SQL INJECTION。
String query="Insert into table values(?,?);";
PreparedStatement stmnt = conn.preparedStatement(query);
stmnt.setString(1, "val1");
stmnt.setString(2, "val2");
关于Java JDBC SQL 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13748811/