We have found a weird issue, that tableExists() will not find an existing table, if the currentSchema URL parameter is less than 8 characters AND contains an underscore (Really?)
We tracked down the issue, and see, that connection.getSchema() always returns a string with minimum length of 8 chars.
For jdbc:db2://localhost:50000/unit:currentSchema=Sch_2; it will return "Sch_2 "
This string is passed into getTables which is effectively translated to CALL SYSIBM.SQLTABLES(?,?,?,?,?) by the JDBC driver
While CALL SYSIBM.SQLTABLES(null,'Sch1 ', null,null,null) will return all tables in Schema Sch1 (does not depend on spaces)
The CALL SYSIBM.SQLTABLES(null,'Sch_1 ', null,null,null) will return nothing.
While the CALL SYSIBM.SQLTABLES(null,'Sch_1', null,null,null) will return all tables of schema Sch_1
We have found a weird issue, that
tableExists()
will not find an existing table, if thecurrentSchema
URL parameter is less than 8 characters AND contains an underscore (Really?)We tracked down the issue, and see, that
connection.getSchema()
always returns a string with minimum length of 8 chars. Forjdbc:db2://localhost:50000/unit:currentSchema=Sch_2;
it will return"Sch_2 "
This string is passed intogetTables
which is effectively translated toCALL SYSIBM.SQLTABLES(?,?,?,?,?)
by the JDBC driverWhile
CALL SYSIBM.SQLTABLES(null,'Sch1 ', null,null,null)
will return all tables in SchemaSch1
(does not depend on spaces) TheCALL SYSIBM.SQLTABLES(null,'Sch_1 ', null,null,null)
will return nothing. While theCALL SYSIBM.SQLTABLES(null,'Sch_1', null,null,null)
will return all tables of schemaSch_1
There are similar issues with underscore like this: https://www.ibm.com/support/pages/apar/PK48336
So as workaround, do not use underscores in schema names. We recommend to use max 8 chars, uppercase and no special chars in schema/db-name.
@rbygrave this is a problem with the DB2 driver/platform which can be easily avoided. Feel free to merge or decline this PR. Cheers Roland