【跪求!急】insert into 语句的语法错误
【在线等。。。】import java.sql.*;
public class CaoBin_Register_Bean {
private Connection con = null; // 数据库连接
private Statement prepstmtForRegister = null;
private Statement prepstmtForLogin = null;
private int userid;
private String username = null;
private String userpass;
private String realname = null;
private int age;
private int sex;
private String e_mail = null;
private String number;
private String grade = null;
// 连接参数
private String DBURL = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=D:\\caobin.mdb";
private String DBUSER = "";
private String DBPASSWORD = "";
private String registerTableSqlStatement = null;
private String loginTableSqlStatement = null;
//2007年12月20日23:11:11
public CaoBin_Register_Bean() {
}
public CaoBin_Register_Bean(int userid, String username, String userpass,
String realname, int age, int sex, String e_mail, String number,
String grade) {
super();
this.userid = userid;
this.username = username;
this.userpass = userpass;
this.realname = realname;
this.age = age;
this.sex = sex;
this.e_mail = e_mail;
this.number = number;
this.grade = grade;
registerTableSqlStatement = "insert into caobin_register_table(userid,username,userpass,realname,age,sex,e_mail,number,grade) values('"+userid+"','"+username+"','"+userpass+"','"+realname+"','"+age+"','"+sex+"','"+e_mail+"','"+number+"','"+grade+"')"; /////////这条语句出现了问题
loginTableSqlStatement = "insert into caobin_login_table(userid,username,userpass) values('"+userid+"','"+username+"','"+userpass+"')"; /////////这条语句能正常插入!为什么上面的不可以?
}
private void ini() throws SQLException {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
if ((con == null) || con.isClosed())
con = DriverManager.getConnection(DBURL,DBUSER,DBPASSWORD);
prepstmtForRegister = con.createStatement();
prepstmtForLogin = con.createStatement();
} catch (SQLException e) {
throw e;
} catch (Exception e) {
System.out.println("load driver error");
}
}
public boolean execUpdate()throws Exception{
try {
ini();
prepstmtForRegister.executeUpdate(registerTableSqlStatement); ///这里执行insert操作! 希望高手指点迷津!不胜感激!!!!
prepstmtForLogin.executeUpdate(loginTableSqlStatement);
return true;
} catch (SQLException e) {
throw e;
} finally {
closeConn();
}
}
private void closeConn() {
try {
if (con != null) {
prepstmtForRegister.close();
prepstmtForLogin.close();
con.close();
prepstmtForRegister = null;
prepstmtForLogin = null;
con = null;
}
} catch (SQLException e) {
e.printStackTrace();
}
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getDBPASSWORD() {
return DBPASSWORD;
}
public void setDBPASSWORD(String dbpassword) {
DBPASSWORD = dbpassword;
}
public String getDBURL() {
return DBURL;
}
public void setDBURL(String dburl) {
DBURL = dburl;
}
public String getDBUSER() {
return DBUSER;
}
public void setDBUSER(String dbuser) {
DBUSER = dbuser;
}
public String getE_mail() {
return e_mail;
}
public void setE_mail(String e_mail) {
this.e_mail = e_mail;
}
public String getGrade() {
return grade;
}
public void setGrade(String grade) {
this.grade = grade;
}
/*public String getLoginTableSqlStatement() {
return loginTableSqlStatement;
}
public void setLoginTableSqlStatement(String loginTableSqlStatement) {
this.loginTableSqlStatement = loginTableSqlStatement;
}*/
public String getNumber() {
return number;
}
public void setNumber(String number) {
this.number = number;
}
public String getRealname() {
return realname;
}
public void setRealname(String realname) {
this.realname = realname;
}
/*public String getRegisterTableSqlStatement() {
return registerTableSqlStatement;
}
public void setRegisterTableSqlStatement(String registerTableSqlStatement) {
this.registerTableSqlStatement = registerTableSqlStatement;
}*/
public int getSex() {
return sex;
}
public void setSex(int sex) {
this.sex = sex;
}
public int getUserid() {
return userid;
}
public void setUserid(int userid) {
this.userid = userid;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getUserpass() {
return userpass;
}
public void setUserpass(String userpass) {
this.userpass = userpass;
}
}
下面是MyEclipse6.0中的语法错误信息!!!
java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] INSERT INTO 语句的语法错误。
at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcStatement.execute(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcStatement.executeUpdate(Unknown Source)
at CaoBin_Register_Bean.execUpdate(CaoBin_Register_Bean.java:86)
at CaoBin_Servlet.doGet(CaoBin_Servlet.java:62)
at CaoBin_Servlet.doPost(CaoBin_Servlet.java:117)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)
at org.apache.tomcat.(JIoEndpoint.java:447)
at java.lang.Thread.run(Unknown Source)