RE: Error connection to oracle database.

"Diego Llorente" <[email protected]>
Newsgroups gmane.comp.java.ejb.middlegen.user
Message-ID <[email protected]>
Hello. I've found a solution to the problem

The problem it's that we don't close the resultset exportedKeyRs in
markFksToUnwantedTables method of class MiddlegenPopulator

the code may be as follows:

   private void markFksToUnwantedTables() throws MiddlegenException {
      ResultSet tableRs = null;
      try {
         tableRs = getMetaData().getTables(_catalog, _schema, null, _types);
         while (tableRs.next()) {
            String tableName = tableRs.getString("TABLE_NAME");
            String tableType = tableRs.getString("TABLE_TYPE");
            // ignore the views, they don't have foreign key relationships
            if (("TABLE".equals(tableType) &&
!_middlegen.containsTable(tableName)) ||
                  ("SYNONYM".equals(tableType) && isOracle())) {
               String ownerSinonimo = null;
               if ("SYNONYM".equals(tableType) && isOracle()) {
                  ownerSinonimo = getSynonymOwner(tableName);
               }
               ResultSet exportedKeyRs = null;
               if (ownerSinonimo != null) {
                  exportedKeyRs = getMetaData().getExportedKeys(_catalog,
ownerSinonimo, tableName);
               }
               else {
                  exportedKeyRs = getMetaData().getExportedKeys(_catalog,
_schema, tableName);
               }
               while (exportedKeyRs.next()) {
                  String fkTableName =
exportedKeyRs.getString("FKTABLE_NAME");
                  String fkColumnName =
exportedKeyRs.getString("FKCOLUMN_NAME");
                  // Mark the fk field as an fk anyway. This will be useful
for column sorting for example
                  if (_middlegen.containsTable(fkTableName)) {
                     DbTable fkTable = _middlegen.getTable(fkTableName);
                     DbColumn fkColumn =
(DbColumn)fkTable.getColumn(fkColumnName);
                     fkColumn.setFk(true);
                  }
               }
               exportedKeyRs.close();//this is the change
            }
         }
      } catch (SQLException e) {
         // schemaRs and catalogRs are only used for error reporting if we
get an exception
         String databaseStructure = getDatabaseStructure();
         _log.error(e.getMessage(), e);
         throw new MiddlegenException("Couldn't get list of tables from
database. Probably a JDBC driver problem." + databaseStructure);
      } finally {
         try {
            tableRs.close();
         } catch (Exception ignore) {
         }
      }
   }



-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training.
Attend Black Hat Briefings & Training, Las Vegas July 24-29 - 
digital self defense, top technical experts, no vendor pitches, 
unmatched networking opportunities. Visit www.blackhat.com
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.