| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2623 人关注过本帖
标题:【跪求!急】insert into 语句的语法错误
只看楼主 加入收藏
清风飒影
Rank: 1
等 级:新手上路
帖 子:45
专家分:0
注 册:2006-11-10
收藏
 问题点数:0 回复次数:1 
【跪求!急】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)
搜索更多相关主题的帖子: insert 语法 语句 
2007-12-23 15:08
清风飒影
Rank: 1
等 级:新手上路
帖 子:45
专家分:0
注 册:2006-11-10
收藏
得分:0 
唉,自己都搞定了,原来是 number变量是关键字 呵呵 o(∩_∩)o...  自己沙发了  

2007-12-23 16:19
快速回复:【跪求!急】insert into 语句的语法错误
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.021949 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved