尝试使用Java检索外键时出现一些错误

时间:2022-06-08 00:07:54

here "path" variable is having address of Database, and "tb" is the Table Name from the database. here I tried to retrieve the foreign key columns and super tables from tables

这里“path”变量具有Database的地址,“tb”是数据库中的Table Name。在这里,我试图从表中检索外键列和超级表

 Connection  con = DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};Dbq="+path);
            ResultSet rs = null;
            DatabaseMetaData meta = con.getMetaData();
            rs = meta.getExportedKeys(con.getCatalog(), null, "tb");
             while (rs.next()) {
               String fkTableName = rs.getString("FKTABLE_NAME");
               String fkColumnName = rs.getString("FKCOLUMN_NAME");
               int fkSequence = rs.getInt("KEY_SEQ");
               System.out.println("getExportedKeys(): fkTableName="+fkTableName);
               System.out.println("getExportedKeys(): fkColumnName="+fkColumnName);
               System.out.println("getExportedKeys(): fkSequence="+fkSequence);
             }

when I tried to run this code I got following error when I tried to generate ResultSet object using getExportedKeys() function.

当我尝试运行此代码时,当我尝试使用getExportedKeys()函数生成ResultSet对象时出现以下错误。

java.sql.SQLException: [Microsoft][ODBC Driver Manager] Driver does not support
this function
        at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6958)
        at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7115)
        at sun.jdbc.odbc.JdbcOdbc.SQLForeignKeys(JdbcOdbc.java:3313)
        at sun.jdbc.odbc.JdbcOdbcDatabaseMetaData.getExportedKeys(JdbcOdbcDataba
seMetaData.java:3139)
        at Frm.actionPerformed(next.java:303)
        at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:17
86)
        at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(Abstra
ctButton.java:1839)
        at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel
.java:420)
        at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258
)
        at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonL
istener.java:245)
        at java.awt.Component.processMouseEvent(Component.java:5100)
        at java.awt.Component.processEvent(Component.java:4897)
        at java.awt.Container.processEvent(Container.java:1569)
        at java.awt.Component.dispatchEventImpl(Component.java:3615)
        at java.awt.Container.dispatchEventImpl(Container.java:1627)
        at java.awt.Component.dispatchEvent(Component.java:3477)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3483
)
        at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3198)

        at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3128)
        at java.awt.Container.dispatchEventImpl(Container.java:1613)
        at java.awt.Window.dispatchEventImpl(Window.java:1606)
        at java.awt.Component.dispatchEvent(Component.java:3477)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:480)
        at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchTh
read.java:201)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
ad.java:151)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)

        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)

        at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)

1 个解决方案

#1


0  

Your hitting MSAccess using an ancient driver. Not all JDBC interactions are supported. You need to use a real database or different driver.

你使用古老的驱动程序击中MSAccess。并非所有JDBC交互都受支持。您需要使用真实数据库或不同的驱动程序。

#1


0  

Your hitting MSAccess using an ancient driver. Not all JDBC interactions are supported. You need to use a real database or different driver.

你使用古老的驱动程序击中MSAccess。并非所有JDBC交互都受支持。您需要使用真实数据库或不同的驱动程序。