简体   繁体   English

这个Exception意味着什么?java.sql.SQLException:一般错误,在Java中使用Access DB?

[英]what does this Exception mean ??java.sql.SQLException: General error , in Java with Access DB?

I'm trying to insert data into the Access DataBase stored on my computer, but when i run this following code an Exception appears 我正在尝试将数据插入存储在我的计算机上的Access数据库中,但是当我运行以下代码时,会出现异常

This is the exception: 这是例外:

Dec 14, 2011 7:22:21 PM Ass3_lab.afterLogin$8 actionPerformed SEVERE: null java.sql.SQLException: General error at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6986) at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7114) at sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(JdbcOdbc.java:3110) at sun.jdbc.odbc.JdbcOdbcStatement.execute(JdbcOdbcStatement.java:338) at sun.jdbc.odbc.JdbcOdbcStatement.executeUpdate(JdbcOdbcStatement.java:288) 2011年12月14日下午7:22:21 Ass3_lab.afterLogin $ 8 actionPerformed SEVERE:null java.sql.SQLException:sun.jdbc.odbc上sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6986)的常规错误。位于sun.jdbc.odbc的sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(JdbcOdbc.java:3110)的sun.jdbc.odbc.JdbcOdbcStatement.execute(JdbcOdbcStatement.java:338)的JdbcOdbc.standardError(JdbcOdbc.java:7114) .JdbcOdbcStatement.executeUpdate(JdbcOdbcStatement.java:288)

I wrote this method to make the insertion: 我写了这个方法来插入:

public void saveDataInDB(int std_id,int course_id,String semester_no) throws SQLException {  
    Connection conn=null;
    PreparedStatement pstmt=null;

    String insertSQL="insert into Registered_course (std_id,course_id,semester_number) values(? , ?,?)";
    try{
        conn=con.getConnection();
        pstmt=conn.prepareStatement(insertSQL);

        pstmt.setInt(1,std_id);
        pstmt.setInt(2,course_id);
        pstmt.setString(3,semester_no);
        pstmt.executeUpdate();

        pstmt.close();
        conn.close();
    }  // end of try
    finally {
        if(conn != null){
            conn.close();
        }
        if (pstmt != null) {
            try {
                pstmt.close();
            } catch (Exception ignore) {
            }
        }
    }
}

And i called the method like this inside an action Listener: 我在一个动作监听器中调用了这样的方法:

save.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e){
        try {
            Login l = new Login();  

            for(int t=0;t<=numberOfRowsInTableOne;t++){
                i.saveDataInDB(l.idFromDB,course_id[t],semester_no);
            }
        } catch (SQLException ex) {
            Logger.getLogger(afterLogin.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
});

Could someone help me solving this problem please? 有人可以帮我解决这个问题吗?

GeneralError is quite misleading. GeneralError非常具有误导性。 There are various reasons why it can happen: 它可能发生的原因有多种:

  1. Incorrect username, password. 用户名,密码不正确。
  2. Difference in bitness of Java and ODBC drivers (check if both java and your odbc drivers are either 32 or 64) Java和ODBC驱动程序的位数差异(检查java和odbc驱动程序是32还是64)
  3. Very annoying but recreating DSN works (no idea why but it sometimes it does). 非常讨厌,但重新创建DSN的工作原理(不知道为什么,但有时它确实如此)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM