DatabaseMetaData problem?

DatabaseMetaData problem?

Post by Zhigang Wa » Fri, 17 Aug 2001 08:26:21



I found this recently.
    Connection conn = ...;
    DatabaseMetaData dbMeta = conn.getMetaData() ;
    for(int i = 0; i < 50; i++){
      ResultSet tableNames = dbMeta.getTables(null,null,"%",null);
      System.out.println("Opened cursor number: " +
getOpenedCursorsNum(conn));
      tableNames.close();
    }

Notice the last line in the for loop. If I dont use this line, my
connection to Oracle database will run out of cursor finally, by
default, I have only 50 cursors.

According JAVA API, any statement and associated resource will be
release when the statement is executed again. I think
oracle.jdbc.driver.OracleDatabaseMetaData should also use some kind of
statement, most probably a PreparedStatement for this purpose. Why the
cursor is not closed?

Does anybody know if this a bug or they have some other important
concerns?

Best wishes,
zhigang,

 
 
 

DatabaseMetaData problem?

Post by Rene Pijlma » Fri, 17 Aug 2001 17:31:37


Zhigang Wang schreef:

Quote:>I found this recently.
>    Connection conn = ...;
>    DatabaseMetaData dbMeta = conn.getMetaData() ;
>    for(int i = 0; i < 50; i++){
>      ResultSet tableNames = dbMeta.getTables(null,null,"%",null);
>      System.out.println("Opened cursor number: " +
>getOpenedCursorsNum(conn));
>      tableNames.close();
>    }

>Notice the last line in the for loop. If I dont use this line, my
>connection to Oracle database will run out of cursor finally, by
>default, I have only 50 cursors.

>According JAVA API, any statement and associated resource will be
>release when the statement is executed again.

Yes, but this code doesn't re-execute a PreparedStatement or
Statement. It calls a factory method (getTables) which returns a new
ResultSet object.

Let's turn the question around. Where in the JDBC documentation did
you read that the ResultSet returned by DatabaseMetaData.getTables()
is implicitly closed when getTables() is executed again?

Quote:>I think
>oracle.jdbc.driver.OracleDatabaseMetaData should also use some kind of
>statement, most probably a PreparedStatement for this purpose. Why the
>cursor is not closed?

Because this code creates a new ResultSet object in every loop.
Internally, its probably not re-executing the same statement, but
instead building a new statement on every call. Hmmm... this does
raise an interesting question: how can getTables() ever close the
statement it has created without closing the ResultSet returned to the
caller?

Anyway, I think its good coding practice to close the ResultSet when
you're done with it.

--


 
 
 

1. DatabaseMetaData problem

Hi,
I use JDK 1.2 JDBC-ODBC bridge to connect to a Microsoft Access 97 database.
However when I try to use the method getTables() in the DatabaseMetaData, I get
an SQLException with a message saying that Microsoft Access 97 is not capable.
Is there any other way to get a list of tables using JDBC from a Microsoft
Access database?

Any help appreciated
Thanks

2. Informix/Career Position/Fla

3. problems with DatabaseMetaData.getColumns()

4. Is there a tool that can restrict users to enter only SELECT SQL commands

5. DatabaseMetaData.getTables() problem

6. PostgreSql JDBC/ODBC Driver

7. Problem with DataBaseMetaData on MySql from Servlet

8. User can not access OLAP Cube after change the SQL Server Account

9. Problem with DatabaseMetaData.getTables and MS/Access

10. MM.MySQL - problems with DatabaseMetaData

11. Different results from DatabaseMetaData and ResultsetMetaData

12. Cant call DatabaseMetaData.getColumns() while in a transaction.

13. Bug in DatabaseMetaData.getProcedures() ??