This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes JDBC 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


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "problem in inserting data into ms access" Watch "problem in inserting data into ms access" New topic
Author

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;
try{
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(orderid);
System.out.println("sql is:"+ sql);
System.out.println("inserting first statement");
st.executeUpdate(sql);
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.

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

I dont see this line your code.


Thanks
Raj
Chris Mabin
Greenhorn

Joined: Jan 10, 2005
Posts: 1
Hi,

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

Chris
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem in inserting data into ms access