• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

problem in inserting data into ms access

 
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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){}
 
Ranch Hand
Posts: 220
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic