• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SQL Exception

 
Ben Koh
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Gurus, I have an SQL string which keep returning SQL syntax exceptions and i have no idea why. Here is the statement:
sql = "INSERT INTO Booking " + "("+
"BookingNo,"+" MovieCode, "+" CustName, "+" NRIC,"+" Telephone,"+" CreditCard,"+
"Quantity,"+" BookingDate, "+" ShowTime, "+" Location,"+" TheatreNo,"+" Price,"+" SeatNumber,"+" Date"+")"
+ "VALUES" + "("+ "'" +BookingNo.getText()+ "'" +" , "+"'" +MovieCode.getText()+ "'"
+"," +"'" +Name.getText()+ "'" +","+"'"+NRIC.getText()+"'"
+"," +"'" +Telephone.getText()+"'"+","+"'"+CreditCard.getText()+ "'" +","+"'"+Quantity.getText()+"'"
+"," +"'" +BookingDate.getText()+"'"+","+"'"+ShowTime.getText()+ "'" +","+"'"+Location.getText()+"'"
+"," +"'" +TheatreNo.getText()+"'"+","+"'"+Price.getText()+ "'" +","+"'"+SeatID.getText()+"'"
+"," +"'" +MovieDate.getText()+"'" + ")";
It keeps returning me

java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Syntax error in INSERT INTO statement.
Any help would be appreciated. Thank you very much!!
 
Jamie Robertson
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The best way to see what SQL is actually being executed in the DB is to do a System.out.println(sql); then paste the printed result into your SQL Editor and run it against the database to see what the results are. By the way, are all columns in the database String/Varchar2? is Date a date field? is Price/SeatNumber number values?
let me know how it goes with the SQL Editor.
Jamie
 
namita pa
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
I want to mention one more thing here.just check whether you are inserting in the correct order.i mean you should write the query to insert the data in the same order as you have in your table.
 
namita pa
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
I want to add one thing here that do check the order in which you are inserting data into the database as this is also a essential requirement that you must insert in the order in which you have columns in the database
all the best
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic