Books
in black and white
Main menu
Share a book About us Home
Books
Biology Business Chemistry Computers Culture Economics Fiction Games Guide History Management Mathematical Medicine Mental Fitnes Physics Psychology Scince Sport Technics
Ads

More Java Pitfalls Share Reactor - Daconta M,C.

Daconta M,C. More Java Pitfalls Share Reactor - Wiley publishing, 2003. - 476 p.
ISBN: 0-471-23751-5
Download (direct link): morejavapitfallssharereactor2003.pdf
Previous << 1 .. 123 124 125 126 127 128 < 129 > 130 131 132 133 134 135 .. 166 >> Next

busy with results for another hstmt
n u s t a .jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6031)
n u s t a .jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:6188)
n u s t a .jdbc.odbc.JdbcOdbc.SQLColumns(JdbcOdbc.java:2174)
n u s t a .jdbc.odbc.JdbcOdbcDatabaseMetaData.getColumns
(JdbcOdbcDatabaseMetaData.java:2576)
at BadResultSet.printMetaDataStuff(BadResultSet.java:92)
at BadResultSet.main(BadResultSet.java:127)
testing MySQL
ResultSet 1: Got table addressbook
ResultSet2: Table addressbook has column ciid
ResultSet2: Table addressbook has column fname
ResultSet2: Table addressbook has column mname
ResultSet2: Table addressbook has column lname
ResultSet2: Table addressbook has column nname
ResultSet 1: Got table channel
ResultSet2: Table channel has column cid
ResultSet2: Table channel has column isa
ResultSet2: Table channel has column name
ResultSet2: Table channel has column description
testing Sybase
ResultSet 1: Got table PERSONNEL
ResultSet2: Table PERSONNEL has column PERSONNEL_ID
ResultSet2: Table PERSONNEL has column SOURCE_ID
ResultSet2: Table PERSONNEL has column PERSONNEL_NUMBER
Listing 41.3 Output of script
The Problem with Multiple Concurrent Result Sets 357
ResultSet 1: Got table UNIT_STATUS ResultSet2: Table UNIT_STATUS has column UNIT_ID ResultSet2: Table UNIT_STATUS has column STATUS_TIME ResultSet2: Table UNIT_STATUS has column SOURCE_ID
testing ORACLE
ResultSet 1: Got table DR$CLASS ResultSet2: Table DR$CLASS has column CLA_ID ResultSet2: Table DR$CLASS has column CLA_NAME ResultSet2: Table DR$CLASS has column CLA_DESC ResultSet2: Table DR$CLASS has column CLA_SYSTEM ResultSet 1: Got table DR$DELETE
ResultSet2: Table DR$DELETE has column DEL_IDX_ID ResultSet2: Table DR$DELETE has column DEL_DOCID ResultSet 1: Got table DR$INDEX ResultSet2: Table DR$INDEX has column IDX_ID ResultSet2: Table DR$INDEX has column IDX_OWNER#
ResultSet2: Table DR$INDEX has column IDX_NAME
java.sql.SQLException: ORA-01000: maximum open cursors exceeded
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:168) at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:208) at oracle.jdbc.ttc7.Oopen.receive(Oopen.java:118) at oracle.jdbc.ttc7.TTC7Protocol.open(TTC7Protocol.java:466) at oracle.jdbc.driver.OracleStatement.<init>(OracleStatement.java:413) at oracle.jdbc.driver.OracleStatement.<init>(OracleStatement.java:432) at oracle.jdbc.driver.OraclePreparedStatement .<init>(OraclePreparedStatement.java:182)
at oracle.jdbc.driver.OraclePreparedStatement .<init>(OraclePreparedStatement.java:165)
at oracle.jdbc.driver.OracleConnection.privatePrepareStatement (OracleConnection.java:604)
at oracle.jdbc.driver.OracleConnection.prepareStatement (OracleConnection.java:485)
at oracle.jdbc.OracleDatabaseMetaData.getColumns (OracleDatabaseMetaData.java:2533)
at BadResultSet.printMetaDataStuff(BadResultSet.java:92) at BadResultSet.main(BadResultSet.java:127)
Listing 41.3 (continued)
Why did some of the databases run through your code without any problems? Why did your queries to the other databases throw exceptions? It revolves around the use of multiple concurrent result sets. Some databases, depending on their configurations,
358 Item 41
can handle having more than one result set open at once. From your output in Listing 41.3, you can see that while SQL Server driver threw an exception immediately when the getColumns() method was called on the DatabaseMetaData object, the Oracle database itself continued to run for a while until its maximum cursors threshold was exceeded.
To write code that is portable across databases, you unfortunately shouldn't make assumptions about what databases can handle having multiple ResultSet objects open at a time. Lucky for you, you went through this testing process by writing the script in Listing 41.2 before you wrote your main query builder application. Other developers could have tested it against one database and deployed the application, only to discover that the application couldn't be ported to a few databases.
How can we solve this problem? A simple change in our design will work. Listing
41.4 shows our new printMetaDataStuff() method that uses an initial ResultSet object to get the table names of the database in line 13 and puts each database table in a LinkedList object in lines 21 to 23. Finally, the initial result set is closed in line 26. In lines 30 to 45, we loop through the linked list of table names that we created, opening up one ResultSet object at a time and printing out the column names for each table.
01 public void printMetaDataStuff() throws Exception
02 {
03 LinkedList ll = new LinkedList();
04 String[] tabletypes = {"TABLE"};
05
06 if (conn == null)
07 {
08 throw new Exception("Could not establish a connection!");
09 }
10
11 DatabaseMetaData dmd = conn.getMetaData();
12
13 ResultSet rs = dmd.getTables(null,null,null,tabletypes);
14
15 if (rs == null)
16 {
17 throw new Exception("No metadata!");
Previous << 1 .. 123 124 125 126 127 128 < 129 > 130 131 132 133 134 135 .. 166 >> Next