INSERT INTO Syntax error ???

  • Thread starter Thread starter tjfaux
  • Start date Start date
T

tjfaux

Guest
Hello All,
I'm am writing an App in Java connecting to an MS Access database. I am now getting a syntax error on the following insert into statement:

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
source = "jdbc:odbc:DKOperations";
connection = DriverManager.getConnection(source);
Statement stmt = connection.createStatement();
String CustInfoTable = "CUSTOMER_INFORMATION";
stmt.executeUpdate("INSERT INTO " + CustInfoTable + " CUSTOMER_FIRST_NAME VALUES " + CustFirstName);


This is the error:
An SQLException occurred: [Microsoft][ODBC Microsoft Access Driver] Syntax error in INSERT INTO statement.

I cannot figure out what the syntax error is. Anyone have an insight on this for me? Most likely something easy that I am missing.


Thanks!
 
Add a variable that builds the insert string so you can examine the string after it is built but before you try to use it. I think the problem will be that the CustFirstName must be surrounded with quotes and it isn't.

This may solve the problem:
stmt.executeUpdate("INSERT INTO " + CustInfoTable + " CUSTOMER_FIRST_NAME VALUES '" + CustFirstName + "'");
 

Users who are viewing this thread

Back
Top Bottom