Java JDBC SQL 异常

标签 java sql jdbc

我目前正在编写一个 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");

在此处查看 How to use preparedstatement in java

关于Java JDBC SQL 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13748811/

相关文章:

java - 将 json 转换为 gson 对象时发生 Gson 错误 预期为 BEGIN_ARRAY,但实际为 BEGIN_OBJECT

sql - 如何找出具有特殊字符的记录不匹配具有相同特殊字符的格式类型?

mysql - 我如何决定何时使用右连接/左连接或内连接或者如何确定哪个表在哪一侧?

mysql - 如何对数据库中的多个表运行相同的查询

java - HP ALM Octane 的数据库连接

java - [警告][插件]插件 jdbc- River,无法调用自定义 onModule 方法

java.lang.NoSuchMethodError : No static method zzb(ZLjava/lang/Object;)V in class Lcom/google/android/gms/common/internal/zzaa; or its super classes 错误

java - 场景构建器预览和执行中的程序之间的不同布局

java - 我的 java 代码无法搜索附近的蓝牙设备

java - 如何使用JAVA在运行时创建多个数据库模式?