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

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

WBOY
WBOYOriginal
2016-06-07 15:32:341334browse

第一 次用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)

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn