>  기사  >  데이터 베이스  >  第一次用access2010连不上,大神帮小弟我看看代码吧.

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

WBOY
WBOY원래의
2016-06-07 15:32:341334검색

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

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.