1. How can I find out the primary key of a table
via JDBC?
2. I'm trying to use JDBC via JDBC-ODBC bridge to
connect to an ODBC MSAccess datasource under
Windows 2000.
The program seems to work fine with the DB
until it tries to fetch the column information
from the RecorSetMetaData. the code and the error
message is as attached.
I have no clue about the exception, could
anybody help?
Thanks,
Meng
But I always get an exception when I try this:
ResultSet rst=
conn.createStatement().executeQuery(sql);
rmd=rst.getMetaData();
int colCount=rmd.getColumnCount();
for (int i=0; i<rmd.getColumnCount(); i++) {
//String attrName = rmd.getColumnName(i);
String test = rmd.getColumnLabel(i);
System.out.println(test);
}
The exception is:
java.sql.SQLException: [Microsoft][ODBC Driver
Manager] Invalid descriptor index
at sun.jdbc.odbc.JdbcOdbc.createSQLException
(JdbcOdbc.java:4089)
at sun.jdbc.odbc.JdbcOdbc.standardError
(JdbcOdbc.java:4246)
at sun.jdbc.odbc.JdbcOdbc.SQLColAttributesString
(JdbcOdbc.java:752)
at
sun.jdbc.odbc.JdbcOdbcResultSetMetaData.getColAttr
ibuteString(JdbcOdbcResultSetMetaData.java:702)
at
sun.jdbc.odbc.JdbcOdbcResultSetMetaData.getColumnL
abel(JdbcOdbcResultSetMetaData.java:327)
at ebgen.Frame1.createEB(Frame1.java, Compiled
Code)
at ebgen.Frame1.generateEJB(Frame1.java,
Compiled Code)
at ebgen.Frame1.actionPerformed(Frame1.java:121)
at javax.swing.AbstractButton.fireActionPerformed
(AbstractButton.java:1066)
at
javax.swing.AbstractButton$ForwardActionEvents.act
ionPerformed(AbstractButton.java:1101)
at
javax.swing.DefaultButtonModel.fireActionPerformed
(DefaultButtonModel.java:378)
at javax.swing.DefaultButtonModel.setPressed
(DefaultButtonModel.java:250)
at
javax.swing.plaf.basic.BasicButtonListener.mouseRe
leased(BasicButtonListener.java:204)
at java.awt.Component.processMouseEvent
(Component.java:3166)
at java.awt.Component.processEvent
(Component.java, Compiled Code)
at java.awt.Container.processEvent
(Container.java, Compiled Code)
at java.awt.Component.dispatchEventImpl
(Component.java, Compiled Code)
at java.awt.Container.dispatchEventImpl
(Container.java, Compiled Code)
at java.awt.Component.dispatchEvent
(Component.java, Compiled Code)
at
java.awt.LightweightDispatcher.retargetMouseEvent
(Container.java, Compiled Code)
at
java.awt.LightweightDispatcher.processMouseEvent
(Container.java, Compiled Code)
at java.awt.LightweightDispatcher.dispatchEvent
(Container.java, Compiled Code)
at java.awt.Container.dispatchEventImpl
(Container.java, Compiled Code)
at java.awt.Window.dispatchEventImpl
(Window.java, Compiled Code)
at java.awt.Component.dispatchEvent
(Component.java, Compiled Code)
at java.awt.EventQueue.dispatchEvent
(EventQueue.java, Compiled Code)
at java.awt.EventDispatchThread.pumpOneEvent
(EventDispatchThread.java, Compiled Code)
at java.awt.EventDispatchThread.pumpEvents
(EventDispatchThread.java:92)
at java.awt.EventDispatchThread.run
(EventDispatchThread.java:83)
Sent via Deja.com http://www.deja.com/
Before you buy.
DatabaseMetaData.getPrimaryKeys
>
> 2. I'm trying to use JDBC via JDBC-ODBC bridge to
> connect to an ODBC MSAccess datasource under
> Windows 2000.
> The program seems to work fine with the DB
> until it tries to fetch the column information
> from the RecorSetMetaData. the code and the error
> message is as attached.
> I have no clue about the exception, could
> anybody help?
You're calling getColumnLabel() with column number = 0. In JDBC all
numbers start from 1.
only if the driver supports this
(the jdbc-odbc-bridge does not!)
--
Klaus Gotthardt