0

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?

0

3 Answers 3

4

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

Sign up to request clarification or add additional context in comments.

Comments

2

, '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.

1 Comment

... and this is why we use prepared statements and parameters.
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.