ここで、「パス」変数はデータベースのアドレスを持ち、「tb」はデータベースからのテーブル名です。ここでは、テーブルから外部キー列とスーパーテーブルを取得しようとしました
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);
}
このコードを実行しようとすると、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)