5 messages in com.mysql.lists.javaRe: getColumns(...) returns empty Res...
FromSent OnAttachments
David M. Karr23 Aug 2001 21:43 
Ext-...@nokia.com23 Aug 2001 22:33 
Venu23 Aug 2001 23:04 
David M. Karr25 Aug 2001 22:38 
David M. Karr26 Aug 2001 11:37 
Subject:Re: getColumns(...) returns empty ResultSet
From:David M. Karr (dmk@earthlink.net)
Date:08/25/2001 10:38:55 PM
List:com.mysql.lists.java

"venu" == venu <ve@mysql.com> writes:

venu> Hi !!! venu> I had a simple sample to test the procedures previously. I extended
the same venu> for getColumns. Please find it as the attachment. Hope this helps you.

I assume you're referring to "TestMyMeta.java"?

venu>
=====================TestMyMeta.java======================================== venu> ============= venu> [skipped lines]

venu> rs = dma.getColumns(null,"test","test_mysql",null); venu> if (rs != null) { venu> ResultSetMetaData md = rs.getMetaData(); venu> int cols = md.getColumnCount(); venu> int row = 0; venu> System.out.println("\t"); venu> for (int i=1; i<=cols; i++) { venu> System.out.print(" "+ md.getColumnLabel(i)); venu> } venu> System.out.println(); venu> while (rs.next()) { venu> row++; venu> String ret = "row "+row+": "; venu> for (int i=1;i<=cols;i++) { venu> ret = ret + rs.getString(i) + " "; venu> } venu> System.out.println(ret); venu> } venu> }

This only helped somewhat, as I still am not aware of any rationale for supplying "null" for the catalog and "test" for the schema. I've tried all the possible permutations I can think of for those parameters. My current test provides the database name for both the "catalog" and "schema". I still get no rows. However, I did add your code described here to get the columns information from the meta data. Ironically, I am able to get the columns information for the ResultSet (from the "getColumns()" request). When I print out the column names, they appear to represent the proper set of columns that should be returned from a "getColumns()" request. However, even though the ResultSet is not null, I still can't get any rows.

I have code like this (my table name is "UserBean"):

--------------------------- DatabaseMetaData dbMetaData = connection.getMetaData(); String dbCatalog = connection.getCatalog(); System.out.println("dbCatalog[" + dbCatalog + "]"); ResultSet rs;

rs = dbMetaData.getColumns(dbCatalog, dbCatalog, "UserBean", null); System.out.println("rs[" + rs + "]");

HashMap userColumnIndices = new HashMap();

if (rs != null) { ResultSetMetaData metadata = rs.getMetaData(); int columns = metadata.getColumnCount(); for (int ctr = 1; ctr <= columns; ++ ctr) { System.out.println("columnLabel[" + metadata.getColumnLabel(ctr)
+ "]"); } }

boolean foundMetaDataRow = false; // Get the column names and their ordinal index. while (rs.next()) { foundMetaDataRow = true; String columnName = rs.getString("COLUMN_NAME"); int ordinalIndex = rs.getInt("ORDINAL_POSITION"); System.out.println("columnName[" + columnName + "] ordinalIndex[" + ordinalIndex + "]"); userColumnIndices.put(columnName.toLowerCase(), new Integer(ordinalIndex)); }

if (!foundMetaDataRow) System.out.println("Didn't find ANY meta data rows.");

---------------------------

Some of my output (running from "ant") is:

--------------------------- [java] dbCatalog[mysql] [java] rs[org.gjt.mm.mysql.jdbc2.ResultSet@113fe2] [java] columnLabel[TABLE_CAT] [java] columnLabel[TABLE_SCHEM] [java] columnLabel[TABLE_NAME] [java] columnLabel[COLUMN_NAME] [java] columnLabel[DATA_TYPE] [java] columnLabel[TYPE_NAME] [java] columnLabel[COLUMN_SIZE] [java] columnLabel[BUFFER_LENGTH] [java] columnLabel[DECIMAL_DIGITS] [java] columnLabel[NUM_PREC_RADIX] [java] columnLabel[NULLABLE] [java] columnLabel[REMARKS] [java] columnLabel[COLUMN_DEF] [java] columnLabel[SQL_DATA_TYPE] [java] columnLabel[SQL_DATETIME_SUB] [java] columnLabel[CHAR_OCTET_LENGTH] [java] columnLabel[ORDINAL_POSITION] [java] columnLabel[IS_NULLABLE] [java] Didn't find ANY meta data rows.

---------------------------