Menu

#1 Problem creating tables

open
nobody
None
5
2003-01-09
2003-01-09
No

Version 0.9.2, in Table.java, you have the following
code to search for primary keys on a table:
ResultSet rspk = null;
while( rs.next() )
{
String pk = rs.getString(4);

stmt = con.createStatement();
rspk = stmt.executeQuery("SELECT " + pk + "
FROM " + tableNameRaw + " WHERE 0 = 1");
rsmd = rspk.getMetaData();

column = new
Column(props,rsmd.getColumnName(1));
column.setColumnType(rsmd.getColumnType(1));

column.setColumnTypeName(SQLTypes.mapTypeName(rsmd.getColumnType(1)));

column.setColumnTypeNameFull(SQLTypes.mapTypeNameFull(rsmd.getColumnType(1)));
column.setIsNullable(false);
column.setIsSearchable(rsmd.isSearchable(1));

primaryKeys.addElement(pk);
primaryKeysForField.addElement(column);
}
rspk.close();

Which will fail if no primary keys are found, as at the
top, you define rspk = null;. If no keys are found,
rs.next() will return false, and not enter the while
loop. Then, when rspk.close() is reached, rspk is
still null, and a NullPointerException is raised. To
fix this, do this:

move rspk.close(); to the inside of the while loop:
while(rs.next())
{
// the rest of your while code here
rspk.close();
}
// rspk.close(); was here, but removed.

I made this change to your source, and the system worked.

Discussion


Log in to post a comment.

MongoDB Logo MongoDB