日期:2014-05-20  浏览次数:20708 次

第一次用access2010连不上,大神帮我看看代码吧......

academy.addItemListener(new ItemListener(){
    public void itemStateChanged(ItemEvent e){
        major=new JComboBox();
        try{
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            String db = "jdbc:odbc:driver={Microsoft Access Driver(*.mdb,*accdb)};DBQ=C:\\Users\\WFVermouth\\Documents\\NetBeansProjects\\GPA\\database\\绩点计算.accdb";
            Connection conn = DriverManager.getConnection(db);
            Statement stmt = conn.createStatement();
            ResultSet rs = stmt.executeQuery("select "+academy.getSelectedItem()+".MName from "+academy.getSelectedItem());
            while (rs.next()) {  
                major.addItem(rs.getString(1));  
            }
            
        }catch(Exception ex){
            ex.printStackTrace();
        }
    }
});


我是想给ComboBox加个监听器,选项改变后连接数据库让另一个ComboBox添加选项,上面这段代码最后打印出来的错误我也看不懂,感觉跟乱码一样。是哪里出错了啊?


报错如下:

java.sql.SQLException: [Microsoft][ODBC ??????????] δ??????????????δ???????????
at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6957)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7114)
at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(JdbcOdbc.java:3073)
at sun.jdbc.odbc.JdbcOdbcConnection.initialize(JdbcOdbcConnection.java:323)
at sun.jdbc.odbc.JdbcOdbcDriver.connect(JdbcOdbcDriver.java:174)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:207)
at gpa.Login$4.itemStateChanged(Login.java:77)
at javax.swing.JComboBox.fireItemStateChanged(JComboBox.java:1205)
at javax.swing.JComboBox.selectedItemChanged(JComboBox.java:1262)
at javax.swing.JComboBox.contentsChanged(JComboBox.java:1309)
at javax.swing.AbstractListModel.fireContentsChanged(AbstractListModel.java:100)
at javax.swing.DefaultComboBoxModel.setSelectedItem(DefaultComboBoxModel.java:88)
at javax.swing.JComboBox.setSelectedItem(JComboBox.java:557)
at javax.swing.JComboBox.setSelectedIndex(JComboBox.java:603)
at javax.swing.plaf.basic.BasicComboPopup$Handler.mouseReleased(BasicComboPopup.java:816)
at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:273)
at java.awt.Component.processMouseEvent(Component.java:6134)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3265)
at javax.swing.plaf.basic.BasicComboPopup$1.processMouseEvent(BasicComboPopup.java:480)
at java.awt.Component.processEvent(Component.java:5899)
at java.awt.Container.processEvent(Container.java:2023)
at java.awt.Component.dispatchEventImpl(Component.java:4501)
at java.awt.Container.dispatchEventImpl(Container.java:2081)
at java.awt.Component.dispatchEvent(Component.java:4331)