James Bender
James Bender

Reputation: 163

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?

Upvotes: 0

Views: 220

Answers (3)

Georgian
Georgian

Reputation: 8960

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

Upvotes: 2

PermGenError
PermGenError

Reputation: 46438

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

Upvotes: 4

Sigal Shaharabani
Sigal Shaharabani

Reputation: 450

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

Upvotes: 0

Related Questions