Heim  >  Artikel  >  Datenbank  >  第一次用access2010连不上,大神帮小弟我看看代码吧.

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

WBOY
WBOYOriginal
2016-06-07 15:32:341332Durchsuche

第一 次用access2010连不上,大神帮我 看看 代码 吧...... academy.addItemListener(newItemListener(){ publicvoiditemStateChanged(ItemEvente){ major=newJComboBox(); try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Stringdb="jdbc:odbc:driver=

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

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


我是想给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)

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn