當我添加兩個字段date
和birthdate
時,我在將數據插入MS Access數據庫時遇到問題。它在插入語句中給出了語法錯誤。我被建議使用PreparedStatement
,但是我不清楚我在代碼中所做的更改。任何人都可以解釋給我嗎?在ms訪問數據庫中插入準備好的語句
int regno= Integer.parseInt(cbregn.getSelectedItem().toString()); //regno=pkey
String nm= cbnm.getSelectedItem().toString();
String place=tfplace.getText();
String kul=tfkul.getText();
String gotra=tfgotra.getText();
String kswami=tfswami.getText();
String raddr=taraddr.getText();
int pincode=Integer.parseInt(tfpcd.getText());//taken datatype number for pincode
int stdcd=Integer.parseInt(tfstdcode.getText());//taken datatype number for stdcode
int tele=Integer.parseInt(tftele.getText());//taken datatype number for teleph no
int mno=(int) Long.parseLong(tfmno.getText());//taken datatype number for mobileno
String email=tfemail.getText();
String website=tfweb.getText();
String education=tfedu.getText();
String branch=tfbrch.getText();
int brthdt=Integer.parseInt(tfbdt.getText());
String bloodgroup=(String)cbbldgrp.getSelectedItem();
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:wanisamajDB");
Statement stmt=con.createStatement();
String qry= "INSERT INTO Registration1(RegistrationNo,SeniorPerson,NativePlace,Kul,Gotra,KulSwami,ResidensialAddress,PinCode,STDcode,TelephoneNo,MobileNo,Email,Website,Education,Branch,BloodGroup) VALUES('"+regno+"','"+nm+"','"+place+"','"+kul+"','"+gotra+"','"+kswami+"','"+raddr+"','"+pincode+"','"+stdcd+"','"+tele+"','"+mno+"','"+email+"','"+website+"','"+education+"','"+branch+"','"+bloodgroup+"')";
// String qry= "INSERT INTO Registration1(RegistrationNo,SeniorPerson,NativePlace,Kul,Gotra,KulSwami,ResidensialAddress,PinCode,STDcode,TelephoneNo,MobileNo,Email,Website,Education,Branch,BloodGroup,Date,BirthDate) VALUES('"+regno+"','"+nm+"','"+place+"','"+kul+"','"+gotra+"','"+kswami+"','"+raddr+"','"+pincode+"','"+stdcd+"','"+tele+"','"+mno+"','"+email+"','"+website+"','"+education+"','"+branch+"','"+bloodgroup+"','"+date+"','"+brthdt+"')";
stmt.executeUpdate(qry);
JOptionPane.showMessageDialog(null,"RECORD IS SAVED SUCCESSFULLY ");
con.close();
}
catch(SQLException eM) {
System.out.println(" "+eM);
JOptionPane.showMessageDialog(null,"RECORD IS NOT SAVED");
}
catch(Exception et)
{
System.out.println("error:"+et.getMessage());
}
這是最近流行的問題http://stackoverflow.com/questions/5570897/error-in-insert-into-statement – Sean 2011-04-09 05:18:57