Hello world,
my program connects to a db2 database and needs to find out the column
names and data types for a specific table.
The code works fine with mysql and derby, but returns an empty
resultset
for the table's metadata with db2.
SELECTs on the connection object work, so there is no problem with the
database connection.
Here's the code:
/* dbxnc is the Connection object */
ResultSet oResults = null;
oResults = dbcnx.getMetaData().getColumns(null, dbName, tableName,
"%");
if (null != oResults)
{
/* just to find out what's going on ... */
if (oResults.getType() != ResultSet.TYPE_FORWARD_ONLY)
{
if (!oResults.first())
{
throw new SQLException("Cannot get first result!");
}
}
else
{
/* the next() call fails! */
if (!oResults.next())
{
throw new SQLException("Cannot forward in result!");
}
}
for (;;)
{
int iType = oResults.getInt("DATA_TYPE");
String sThisColName = oResults.getString("COLUMN_NAME");
System.out.println(sThisColName + " =" + iType);
if (!oResults.next())
{
break;
}
}
oResults.close();
}
Has anyone a idea what I am doing wrong?
Thanks for any help!
Joerg