• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem in inserting data into ms access

 
sreenivas jeenor
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 220
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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

Chris
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic