Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Syntax error in INSERT INTO statement

 
andy iott
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi-

I am writing a java app that interfaces an Access 2000 DB via JDBC-ODBC. I keep getting a syntax error on the following sql statement:

String sql = "INSERT INTO REQUIREMENTS (DOC_ID, ORDER_DATE, ORDER_TYPE, CUST_CODE, CUST_NAME, CUST_ADDRESS_ST, CUST_ADDRESS_CITY, SPO_ORDER_NO, POCONTROL_NO, LIN_ITEM, CUST_PART_NO, OTHER_PART_NO, WTN, CUST_BINPART_NO, DESC, ORDER_NOTES, LIN_ITEM_NOTES, CUSTOMER) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";

PreparedStatement stmt = con.prepareStatement(sql);

pstmt.setString(1,docID);
pstmt.setString(2,orderDate);
pstmt.setString(3,orderType);
pstmt.setString(4,custCode);
pstmt.setString(5,shipToName);
pstmt.setString(6,shipTo1);
pstmt.setString(7,shipTo2);
pstmt.setString(8,spoOrderNo);
pstmt.setString(9,poNo);
pstmt.setInt(10,Integer.parseInt(linNo));
pstmt.setString(11,gmPn);
pstmt.setString(12,acdPn);
pstmt.setInt(13,Integer.parseInt(qty));
pstmt.setString(14,custBin);
pstmt.setString(15,desc);
pstmt.setString(16,orderNotes);
pstmt.setString(17,linNotes);
pstmt.setString(18,cust);
System.out.println(sql);

pstmt.executeUpdate();

error produced:

Microsoft][ODBC Microsoft Access Driver] Syntax error in INSERT INTO statement.

I have looked at this sucker for 2 days now. I can insert records for some fields if I limit the fields inserted to 6 or so, but I am unable to insert this entire statement and can find no correlation to what fields insert and which cause the syntax error. I have double checked that all data types correspond. I have also tried this with a Statement as well.

Any feedback would be EXTREMELY appreciated.

Thank you,

AI
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64973
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you try putting a space between "VALUES" and "("? Remember that Access isn't exactly the caviar of databases.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34672
367
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Andy,
I'm suprised the database lets you create a field named "DESC". I thought this was a reserved word. Does the query work without that field?

Welcome to Javaranch!

[edited to fix typo]
[ September 23, 2004: Message edited by: Jeanne Boyarsky ]
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you show some failing output with your System.out.println(sql);?
 
andy iott
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It was the field name 'DESC'...I knew it was a stupid one!! At least it wasn't a space or "'"!!! I needed a fresh set of eyeballs.

THANKS for the response guys.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic