0

我有一个到 MS Access 数据库的 JDBC:ODBC 连接,该数据库使用 DButils 填充 JTable。我的基本 SQL 查询工作正常,直到我尝试 COUNT 函数,然后在尝试填充我的 JTable 时出现错误。查询可以很好地填充 JTextArea,所以我知道查询没问题。我的代码低于任何帮助将不胜感激。

    import javax.swing.JFrame;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import java.sql.*;
    import net.proteanit.sql.DbUtils;

public class table {
    Connection con;
    Statement st;
    ResultSet rs;

    public table(){
        connect();
    }
    public void connect(){

        JTable tbl = new JTable();
        tbl.setDefaultEditor(Object.class, null);
        JFrame resFrame = new JFrame("Results");
        resFrame.setLayout(null);
        resFrame.setSize(525, 445);
        resFrame.setVisible(true);
        JScrollPane tsp = new JScrollPane(tbl);
        tsp.setLocation(20, 20);
        resFrame.add(tsp);
        tbl.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
        tsp.setSize(370,375);

        String sql = "SELECT Club, COUNT('memberID') AS total FROM Members_Table, Club_Table WHERE Club_Table.clubID=Members_Table.clubID GROUP BY Club";

        try{

            String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
            Class.forName(driver);
            String db = "jdbc:odbc:ITUKdb";
            con = DriverManager.getConnection(db);
            st = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
            rs = st.executeQuery(sql);
            tbl.setModel(net.proteanit.sql.DbUtils.resultSetToTableModel(rs));
        }catch(Exception ex){

        }
    }
}

我得到的错误如下

java.sql.SQLException: [Microsoft][ODBC Driver Manager] Invalid cursor state
    at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6956)
    at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7113)
    at sun.jdbc.odbc.JdbcOdbc.SQLGetDataString(JdbcOdbc.java:3906)
    at sun.jdbc.odbc.JdbcOdbcResultSet.getDataString(JdbcOdbcResultSet.java:5697)
    at sun.jdbc.odbc.JdbcOdbcResultSet.getString(JdbcOdbcResultSet.java:353)
    at sun.jdbc.odbc.JdbcOdbcResultSet.getObject(JdbcOdbcResultSet.java:1677)
    at net.proteanit.sql.DbUtils.resultSetToTableModel(DbUtils.java:28)
    at trial.table.connect(table.java:53)
    at trial.table.<init>(table.java:22)
    at trial.ITUKSQL.main(ITUKSQL.java:212)
4

1 回答 1

0

排序必须删除

ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE

 st = con.createStatement();
于 2012-08-16T14:19:02.280 回答