aspose file tools*
The moose likes JDBC and the fly likes Syntax  error in INSERT INTO statement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Syntax  error in INSERT INTO statement" Watch "Syntax  error in INSERT INTO statement" New topic
Author

Syntax error in INSERT INTO statement

andy iott
Greenhorn

Joined: Sep 23, 2004
Posts: 3
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

Joined: Jan 10, 2002
Posts: 61658
    
  67

Did you try putting a space between "VALUES" and "("? Remember that Access isn't exactly the caviar of databases.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30957
    
158

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 ]

[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

Can you show some failing output with your System.out.println(sql);?


http://home.arcor.de/hirnstrom/bewerbung
andy iott
Greenhorn

Joined: Sep 23, 2004
Posts: 3
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Syntax error in INSERT INTO statement