It's not a secret anymore!
The moose likes JDBC and Relational Databases and the fly likes problem in inserting data into ms access Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "problem in inserting data into ms access" Watch "problem in inserting data into ms access" New topic

problem in inserting data into ms access

sreenivas jeenor
Ranch Hand

Joined: Jan 09, 2005
Posts: 125
i m getting error SQLException [microsoft][ODBC Microsoft Access Driver] Syntax error in insert into statement.

i am using MS ACCESS as my backned.
i am having a table called order with the following as fields,namely
Field Name DataType
orderid Number(long integer)
contactname text
deliveryaddress text
ccname text
ccnumber text
ccexpirydate text

in my java program

long orderid= System.currentTimeMillis();

Connection con=null;
con = DriverManager.getConnection(jdbc dbc:mydsn);
Statement st = con.createStatement();
String sql="INSERT INTO order(orderid,contactname,deliveryaddress,ccname,ccnumber,ccexpirtdate)VALUES("+orderid+",'"+contactname+"','"+deliveryaddress+"','"+ccname+"','"+ccnumber+"','"+ccexpirydate+"')";
System.out.println("sql is:"+ sql);
System.out.println("inserting first statement");
System.out.println("first statement inserted");
}catch(Exception e){}
Rajendar Goud
Ranch Hand

Joined: Mar 06, 2002
Posts: 220
Hi sanjeev,
i hadnt worked recently on access but for making the DataBase Connection,doesnt it need to get an instance of the Driver.


I dont see this line your code.

Chris Mabin

Joined: Jan 10, 2005
Posts: 1

Syntax error is occurring because the variable is defined as ccexpirydate,
but the Insert string is using ccexpirtdate.

I agree. Here's the link:
subject: problem in inserting data into ms access
jQuery in Action, 3rd edition