简体   繁体   中英

Java JDBC SQL Exception

I am currently working on a script in Java to import a bunch of books from a lengthy plain text file to a database. I have all of the books parsed into book objects and am trying to write them to the database. However, I get a missing comma exception "ORA-00917: missing comma" on the Following String:

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' )

I cannot see where there is a comma missing. Could there be another reason for this exception?

The error is obvious, you are missing a comma somewhere in your insert statement.

However, i strongly recommend you to use PreparedStatement rather than simple Statement when performing SQL queries using JDBC to prevent SQL INJECTION.

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

Check here about How to use preparedstatement in java

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

Right there.
Notice how you missed a tick after (48456). Probably because the (CRN's) part.

Also, I recommend using a record for ease of programming. Inserting values like that is just messy. :) Keep up the good work.

'Ember, Carol & Ember, Melvin,' is probably causing the problem Try 'Ember, Carol &' || ' Ember, Melvin,' 'Ember, Carol &' || ' Ember, Melvin,'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM