Monday, February 20, 2012

jdbc driver getTables(String , String ,Sring ,String[] )can't get tables whose catalog is pure

i have a database named "1", then i want to get the tables which type is "TABLE" under this catalog but it can't be done.
Check the kode:
conn.setCatalog("\"1\"");
DatabaseMetaData meta = conn.getMetaData();
ResultSet tables = meta.getTables("\"1\"", "dbo","ttt" , new String [] {"TABLE"});
if i change the last sentence to :
ResultSet tables = meta.getTables("1", "dbo","ttt" , new String [] {"TABLE"}), it still can't be done.
it work when "ResultSet tables = meta.getTables(null, "dbo","ttt" , new String [] {"TABLE"})

I tested this with the SQL Server 2005 JDBC driver and it worked fine.

I created a database named ["1"].

Which SQL Server JDBC driver are you using?

Also try bracketizing the database name like so, this will probably make it work:

ResultSet tables = meta.getTables("[\"1\"]", "dbo","ttt" , new String [] {"TABLE"});

Matt

|||k, i am working under sqlserver 2000 , i change the kode as u do, but it still can't work fine.

steps:
create database through sql : "create database 1".
change the kode to :
ResultSet tables = meta.getTables("[\"1\"]", null,null, new String [] {"TABLE"});
but it still can't work.no table returned.
Have u any idear?

|||i also tried this:
conn.getCatalog() returns "1";
but meta.getCatalogs returns 1;
is it a bug?|||

If you created the database named 1, then use 1 and not "1", so:

ResultSet tables = meta.getTables("[1]", null,null, new String [] {"TABLE"});

Also, if you have SQL Server Profiler you can see what it sent to the SQL Server.

With the SQL 2005 driver I see:

exec sp_tables @.table_qualifier = '"1"', @.table_owner = 'dbo', @.table_name = null , @.table_type = '''TABLE'''

This might help you figure out what the SQL 2000 driver is doing wrong.

I have the SQL 2000 driver setup on my machine I will give it a quick test.

|||

Yes I tested with SQL 2000 JDBC driver and this failed, so it is a bug.

Works fine with SQL 2005 JDBC driver.

I reported this bug to the JDBC PM.

|||3X a lot.

No comments:

Post a Comment