Annotation of FM2SQL/DBBean.java, revision 1.2

1.1       rogo        1: import java.io.ByteArrayOutputStream;
                      2: import java.io.PrintStream;
                      3: import java.sql.*;
                      4: import java.util.*;
                      5: import com.fmi.jdbc.*;
                      6: 
                      7: /**
                      8:  *
                      9:  *
                     10:  * DBBean - Database bean
                     11:  *
                     12:  *<p> a Javabean  to perform queries on a JDBC Database,
                     13:  * or excute any other SQL statement
                     14:  * </p>
                     15:  * <p>
                     16:  * Usage:
                     17:  * <pre>
                     18:  *   DBBean bean = new DBBean();
                     19:  * // setting user and passwd
                     20:  *  bean.setUserAndPasswd("bla","bla");
                     21:  *  try
                     22:  *  {
                     23:  *    bean.setConnection("jdbc:fmpro:http://localhost");
                     24:  *    Vector names=bean.getTableNames();
                     25:  *    Vector[] result=bean.getQueryData(names.get(0).toString());
                     26:  *  // print results to screen
                     27:  *     for(int i=0;i&lt;result[1].size();++i)
                     28:  *     {
                     29:  *       //print Header
                     30:  *       System.out.print(" "+result[1].get(i));
                     31:  *     }
                     32:  *  System.out.println();
                     33:  *  for(int j=0;j&lt;result[0].size();++j)
                     34:  *  {
                     35:  *     Vector row=(Vector)result[0].get(j);
                     36:  *     //print rows
                     37:  *     for(int k=0;k&lt;row.size();++k)
                     38:  *     System.out.print(" "+row.get(k));
                     39:  *     System.out.println();
                     40:  *  }
                     41:  * } catch(Exception e)
                     42:  *   {
                     43:  *     System.out.println("Error while connecting to database"+ e);
                     44:  *   }
                     45:  * </pre>
                     46:  *
                     47:  * </p>
                     48:  * @author rogo
                     49:  */
                     50: public class DBBean
                     51: {
                     52:   Connection connection;
                     53:   String url = "";
                     54:   DatabaseMetaData dbMetaData;
                     55:   Vector columnNames;
                     56:   String user = (System.getProperty("user.name") == null) ? "" : System.getProperty("user.name"); //"postgres";
                     57:   String passwd = ""; //"3333";//"rogo";
                     58:   public int maxHits = 10;
                     59:   ResultSet result;
                     60:   String quoteChar = "";
                     61:   Hashtable connectionPool = new Hashtable();
                     62:   public ResultSetMetaData metaData;
                     63:   // register DataBase Drivers
                     64:   static {
                     65:     try
                     66:     {
                     67:       DriverManager.registerDriver(new com.fmi.jdbc.JdbcDriver());
                     68:       DriverManager.registerDriver((Driver) Class.forName("org.postgresql.Driver").newInstance());
                     69:       DriverManager.registerDriver((Driver) Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance());
                     70:       DriverManager.registerDriver((Driver) Class.forName("com.mysql.jdbc.Driver").newInstance());
                     71: 
                     72:       // wait a maximum of 10 seconds when attempting to establish a connection
                     73:       DriverManager.setLoginTimeout(10);
                     74:     } catch (Exception e)
                     75:     {
                     76:       System.out.println(e);
                     77:     }
                     78:   }
                     79:   /**
                     80:    * Constructs a database bean
                     81:    */
                     82:   public DBBean()
                     83:   {
                     84: 
                     85:   }
                     86:   /**
                     87:    *Constructs a database bean
                     88:    * and tries to connect to database
                     89:    *specified in the jdbcConnectionURL
                     90:    * @param jdbcConnectionURL url to connect to database
                     91:     */
                     92: 
                     93:   public DBBean(String jdbcConnectionURL) throws Exception
                     94:   {
                     95: 
                     96:     this.url = jdbcConnectionURL;
                     97: 
                     98:     connection = getConnection();
                     99:     if (connection == null)
                    100:       return;
                    101:     // get the meta data for the current connection
                    102:     DatabaseMetaData dbMetaData = (DatabaseMetaData) connection.getMetaData();
                    103:     quoteChar = dbMetaData.getIdentifierQuoteString();
                    104:     if (quoteChar == null)
                    105:       quoteChar = "\""; // needed for postgres
                    106: 
                    107:     // create the root node of the tree
                    108:     // get the open tables from the current connection; the FileMaker Pro
                    109:     // JDBC driver ignores all of the parameters to this method
                    110: 
                    111:     // iterate over the table names and add them to the root node of the tree
                    112: 
                    113:   }
                    114:   /**
                    115:    * sets the maximum number of hits
                    116:    */
                    117:   public void setMaxHits(int maxHits)
                    118:   {
                    119:     this.maxHits = maxHits;
                    120:   }
                    121:   /**
                    122:     * gets the maximum number of hits
                    123:     */
                    124:   public int getMaxHits()
                    125:   {
                    126:     return maxHits;
                    127:   }
                    128: 
                    129:   /**
                    130:    * returns the Connection if null creates a new one from the url property.
                    131:    *
                    132:    */
                    133:   public Connection getConnection() throws Exception
                    134:   {
                    135:     ConnectionPool conPool = (ConnectionPool) connectionPool.get(url);
                    136:     if (conPool == null)
                    137:     {
                    138:       connection = DriverManager.getConnection(url, user, passwd);
                    139:       connectionPool.put(url, new ConnectionPool(url, user, passwd, connection));
                    140:     } else
                    141:     {
                    142:       if (!conPool.user.equals(user) || !conPool.passwd.equals(passwd))
                    143:       {
                    144:         conPool.con.close();
                    145:         conPool.user = user;
                    146:         conPool.passwd = passwd;
                    147: 
                    148:       }
                    149:       connection = conPool.con;
                    150:       if (connection.isClosed())
                    151:       {
                    152:         System.out.println("Made new connection!!!");
                    153:         connection = DriverManager.getConnection(conPool.url, conPool.user, conPool.passwd);
                    154:         conPool.con = connection;
                    155:       }
                    156:     }
                    157:     if (url != "" && connection == null)
                    158:       connection = DriverManager.getConnection(url, user, passwd);
                    159:     dbMetaData = connection.getMetaData();
                    160:     quoteChar = dbMetaData.getIdentifierQuoteString();
                    161:     if (quoteChar == null)
                    162:       quoteChar = "\""; // needed for postgres
                    163: 
                    164:     return connection;
                    165:   }
                    166:   /**
                    167:    * sets the connection of this DBBean to the database specified in the url
                    168:    *  property
                    169:    */
                    170:   public void setConnection(String url) throws Exception
                    171:   {
                    172:     this.url = url;
                    173:     if (url != "")
                    174:       connection = DriverManager.getConnection(url, user, passwd);
                    175:     dbMetaData = connection.getMetaData();
                    176:     quoteChar = dbMetaData.getIdentifierQuoteString();
                    177:     if (quoteChar == null)
                    178:       quoteChar = "\""; // needed for postgres
                    179:   }
                    180:   /**
                    181:    * sets the connection of this DBBean to the database specified in the url
                    182:    * and the url,user and passwd property of this DBBean instance
                    183:    */
                    184:   public void setConnection(String url, String user, String passwd) throws Exception
                    185:   {
                    186:     this.user = user;
                    187:     this.passwd = passwd;
                    188:     this.url = url;
                    189:     if (url != "")
                    190:       connection = DriverManager.getConnection(url, user, passwd);
                    191:     dbMetaData = connection.getMetaData();
                    192:     quoteChar = dbMetaData.getIdentifierQuoteString();
                    193:     if (quoteChar == null)
                    194:       quoteChar = "\""; // needed for postgres
                    195:   }
                    196: 
                    197:   /**
                    198:    * returns a Vector containing the Tablenames or an error message in the Vector
                    199:    */
                    200:   public Vector getTableNames()
                    201:   {
                    202:     Vector tableNameVec = new Vector();
                    203:     try
                    204:     {
                    205:       if (connection == null)
                    206:       {
                    207:         Vector vec = new Vector();
                    208:         vec.add("no database connection");
                    209:         return vec;
                    210:       }
                    211:       if (dbMetaData == null)
                    212:         dbMetaData = connection.getMetaData();
                    213:       ResultSet tableNames = dbMetaData.getTables(null, null, null, null);
                    214:       // System.out.println(dbMetaData.supportsAlterTableWithAddColumn());
                    215:       // iterate over the table names and add them to the root node of the tree
                    216: 
                    217:       while (tableNames.next())
                    218:       {
                    219:         String tableName = tableNames.getString("TABLE_NAME");
                    220:         tableNameVec.add(tableName);
                    221: 
                    222:       }
                    223:     } catch (Exception e)
                    224:     {
                    225:       e.printStackTrace();
                    226:     }
                    227:     return tableNameVec;
                    228:   }
                    229:   /**
                    230:    * returns a Vector containing the Tablenames or an error message in the Vector
                    231:    */
                    232:   public Vector getTableNames(String catalog)
                    233:   {
                    234:     Vector tableNameVec = new Vector();
                    235:     try
                    236:     {
                    237:       if (connection == null)
                    238:       {
                    239:         Vector vec = new Vector();
                    240:         vec.add("no database connection");
                    241:         return vec;
                    242:       }
                    243:       setConnection(url.substring(0, url.lastIndexOf("/") + 1) + catalog);
                    244:       if (dbMetaData == null)
                    245:         dbMetaData = connection.getMetaData();
                    246:       System.out.println("catalog " + catalog + " " + dbMetaData.getCatalogSeparator() + " " + url.substring(0, url.lastIndexOf("/") + 1));
                    247:       ResultSet tableNames = dbMetaData.getTables(null, null, null, null);
                    248:       // System.out.println(dbMetaData.supportsAlterTableWithAddColumn());
                    249:       // iterate over the table names and add them to the root node of the tree
                    250: 
                    251:       while (tableNames.next())
                    252:       {
                    253:         String tableName = tableNames.getString("TABLE_NAME");
                    254:         tableNameVec.add(tableName);
                    255: 
                    256:       }
                    257:     } catch (Exception e)
                    258:     {
                    259:       e.printStackTrace();
                    260:     }
                    261:     return tableNameVec;
                    262:   }
                    263: 
                    264:   /**
                    265:    * returns a Vector containing the Catalog or an error message in the Vector
                    266:    */
                    267:   public Vector getCatalogs()
                    268:   {
                    269:     Vector tableNameVec = new Vector();
                    270:     try
                    271:     {
                    272:       if (connection == null)
                    273:       {
                    274:         Vector vec = new Vector();
                    275:         vec.add("no database connection");
                    276:         return vec;
                    277:       }
                    278:       if (dbMetaData == null)
                    279:         dbMetaData = connection.getMetaData();
                    280:       ResultSet tableNames = dbMetaData.getCatalogs();
                    281:       // System.out.println(dbMetaData.supportsAlterTableWithAddColumn());
                    282:       // iterate over the table names and add them to the root node of the tree
                    283:       System.out.println(tableNames.getMetaData().getColumnName(1));
                    284:       while (tableNames.next())
                    285:       {
                    286:         String tableName = tableNames.getString(1);
                    287:         tableNameVec.add(tableName);
                    288:         //tableName = tableNames.getString(1);
                    289:         //tableNameVec.add(tableName);
                    290: 
                    291:       }
                    292:     } catch (Exception e)
                    293:     {
                    294:       e.printStackTrace();
                    295:     }
                    296:     return tableNameVec;
                    297:   }
                    298: 
                    299:   /**
                    300:   * returns a Vector containing the layoutNames for the specified Table
                    301:   * if the database supports this otherwise Vector containing an empty String
                    302:   */
                    303: 
                    304:   public Vector getLayoutNames(String tableName) throws SQLException
                    305:   {
                    306:     Vector layouts = new Vector();
                    307:     if (dbMetaData instanceof DatabaseMetaDataExt)
                    308:       layouts.add("");
                    309:     if (dbMetaData == null)
                    310:       dbMetaData = connection.getMetaData();
                    311: 
                    312:     if (dbMetaData instanceof DatabaseMetaDataExt)
                    313:     {
                    314:       ResultSet layoutNames = ((DatabaseMetaDataExt) dbMetaData).getLayouts(null, null, tableName, null);
                    315: 
                    316:       // iterate over the layout names and add them to the "Layouts" node
                    317:       while (layoutNames.next())
                    318:         layouts.add(layoutNames.getString("LAYOUT_NAME"));
                    319:     }
                    320:     return layouts;
                    321:   }
                    322:   /**
                    323:    *   Returns the result for select * from table
                    324:    *   with maxHits = 500 default value
                    325:    */
                    326:   public Vector[] getQueryData(String table) throws SQLException
                    327:   {
                    328: 
                    329:     return getQueryData("SELECT * from " + quoteChar + table + quoteChar, maxHits);
                    330: 
                    331:   }
                    332: 
                    333:   /**
                    334:    *    Returns the result of the query
                    335:    *    or an Vector array of Vectors containing error messages
                    336:    */
                    337:   public Vector[] getQueryData(String query, FM2SQL.ProgressDialog dialog, int maxHits) throws SQLException
                    338:   {
                    339:     long timeStart = System.currentTimeMillis();
                    340:     ResultSet resultSet = null;
                    341:     if (connection == null)
                    342:     {
                    343:       Vector[] noData = new Vector[2];
                    344:       //System.out.println("Exception occured");
                    345:       noData[1] = new Vector();
                    346:       Vector vec2 = new Vector();
                    347:       noData[0] = new Vector();
                    348:       vec2.add("no Connection available");
                    349:       noData[0].add(vec2);
                    350:       noData[1].add("Exception occured! No results available");
                    351:       //noData[1].add("no Results were produced");
                    352: 
                    353:       return noData;
                    354:     }
                    355:     if (dialog != null)
                    356:       dialog.progress.setValue(0);
                    357: 
                    358:     resultSet = makeQuery(query, maxHits);
                    359: 
                    360:     metaData = resultSet.getMetaData();
                    361:     int columnCount = metaData.getColumnCount();
                    362:     int rowCount = 0;
                    363:     if (maxHits == 0)
                    364:       rowCount = (metaData instanceof ResultSetMetaDataExt) ? 1000 : getRowCount(query);
                    365:     else
                    366:       rowCount = maxHits;
                    367:     int counter = 0;
                    368:     Vector tableData = new Vector();
                    369:     Vector tableRow = new Vector();
                    370:     //  System.out.println("rowCount "+rowCount+" "+maxHits);
                    371:     try
                    372:     {
                    373:       while ((tableRow = getNextRow()) != null)
                    374:       {
                    375:         counter++;
                    376:         if (dialog != null)
                    377:           dialog.progress.setValue((int) ((double) counter / (double) rowCount * 100.0));
                    378: 
                    379:         tableData.add(tableRow);
                    380: 
                    381:       }
                    382:     } catch (Exception e)
                    383:     {
                    384:       // TODO Auto-generated catch block
                    385:       e.printStackTrace();
                    386:     }
                    387: 
                    388:     // retrieve the column names from the result set; the column names
                    389:     // are used for the table header
                    390:     columnNames = new Vector();
                    391: 
                    392:     for (int i = 1; i <= columnCount; i++)
                    393:       columnNames.addElement(metaData.getColumnName(i));
                    394:     Vector data[] = new Vector[2];
                    395:     data[0] = tableData;
                    396:     data[1] = columnNames;
                    397:     System.out.println("Rows " + tableData.size() + " " + ((Vector) tableData.get(0)).size());
                    398:     long timeEnd = System.currentTimeMillis();
                    399:     System.out.println("Time needed for query and data retrieval " + (timeEnd - timeStart) + " ms");
                    400:     return data;
                    401:   }
                    402:   /**
                    403:    *    Returns the result of the query
                    404:    *    or an Vector array of Vectors containing error messages
                    405:    */
                    406:   public Vector[] getQueryData(String query, int maxHits) throws SQLException
                    407:   {
                    408:     long timeStart = System.currentTimeMillis();
                    409:     ResultSet resultSet = null;
                    410:     if (connection == null)
                    411:     {
                    412:       Vector[] noData = new Vector[2];
                    413:       //System.out.println("Exception occured");
                    414:       noData[1] = new Vector();
                    415:       Vector vec2 = new Vector();
                    416:       noData[0] = new Vector();
                    417:       vec2.add("no Connection available");
                    418:       noData[0].add(vec2);
                    419:       noData[1].add("Exception occured! No results available");
                    420:       //noData[1].add("no Results were produced");
                    421: 
                    422:       return noData;
                    423:     }
                    424:     resultSet = makeQuery(query, maxHits);
                    425:     metaData = resultSet.getMetaData();
                    426:     int columnCount = metaData.getColumnCount();
                    427: 
                    428:     Vector tableData = new Vector();
                    429:     while (resultSet.next())
                    430:     {
                    431:       //System.out.println("datatype "+(Types.LONGVARCHAR ==metaData.getColumnType(3)));
                    432:       Vector tableRow = new Vector(), m_columnClasses = new Vector();
                    433:       for (int i = 1; i <= columnCount; i++)
                    434:       {
                    435:         // repeating fields and fields from related databases may contain
                    436:         // multliple data values; the data values are stored using
                    437:         // a Vector which is then added to the tableRow
                    438:         //      if (metaData instanceof ResultSetMetaDataExt)
                    439:         if ((metaData instanceof ResultSetMetaDataExt) && (((ResultSetMetaDataExt) metaData).isRelated(i) || ((ResultSetMetaDataExt) metaData).isRepeating(i)))
                    440:         {
                    441:           //System.out.println("Related fields");
                    442:           // retrieve the repeating or related field contents as a
                    443:           // com.fmi.jdbc.Array via the ResultSet.getObject method
                    444:           com.fmi.jdbc.Array array = (com.fmi.jdbc.Array) resultSet.getObject(i);
                    445:           //            create a Vector for storing all of the data values
                    446:           ArrayList columnData = new ArrayList();
                    447: 
                    448:           try
                    449:           {
                    450: 
                    451:             // call the Array.getStringArray method since the data will
                    452:             // only be displayed
                    453:             Object[] fieldData = (Object[]) array.getArray();
                    454: 
                    455:             if (fieldData != null)
                    456:             {
                    457:               // add each value to the Vector
                    458:               for (int j = 0; j < fieldData.length; j++)
                    459:               {
                    460:                 if (fieldData[j] != null)
                    461:                   columnData.add(fieldData[j]);
                    462:               }
                    463: 
                    464:             }
                    465:           } catch (Exception e)
                    466:           {
                    467:             //System.out.println(e);
                    468:           }
                    469:           if (columnData.isEmpty())
                    470:             tableRow.add(null);
                    471:           else
                    472:             tableRow.addElement(columnData);
                    473:           //System.out.println(columnData);
                    474:           //System.out.println("Related fields"+columnData.size()+" "+tableRow.size());
                    475: 
                    476:           m_columnClasses.addElement(java.util.Vector.class);
                    477:         } else if (metaData.getColumnType(i) == Types.LONGVARBINARY)
                    478:         {
                    479:           // use the ResultSet.getObject method for retrieving images
                    480:           // from FileMaker Pro container fields; the ResultSet.getObject
                    481:           // method returns a java.awt.Image object for FileMaker Pro
                    482:           // container fields
                    483:           try
                    484:           {
                    485: 
                    486:             tableRow.addElement(resultSet.getObject(i));
                    487:           } catch (Exception e)
                    488:           {
                    489:             // TODO Auto-generated catch block
                    490:             //e.printStackTrace();
                    491:             tableRow.addElement(null);
                    492:           }
                    493:           //tableRow.addElement("Picture ignored");
                    494:           m_columnClasses.addElement(java.awt.Image.class);
                    495:         } else if (metaData.getColumnType(i) == Types.TIME)
                    496:         {
                    497:           // use the ResultSet.getObject method for retieving images
                    498:           // from FileMaker Pro container fields; the ResultSet.getObject
                    499:           // method returns a java.awt.Image object for FileMaker Pro
                    500:           // container fields
                    501:           try
                    502:           {
                    503:             tableRow.addElement(resultSet.getTime(i).toString());
                    504:             m_columnClasses.addElement(java.sql.Time.class);
                    505:           } catch (Exception e)
                    506:           {
                    507: 
                    508:             String value = resultSet.getString(i);
                    509:             if (value != null)
                    510:             {
                    511:               //System.out.println("SQLTime new "+Time.valueOf("17:00:00").toString());
                    512:               int index = 0;
                    513:               for (int j = 0; j < value.length(); ++j)
                    514:               {
                    515:                 if (!Character.isLetter(value.charAt(j)))
                    516:                   index = j + 1;
                    517:                 else
                    518:                   break;
                    519:               }
                    520: 
                    521:               tableRow.addElement(value.substring(0, index));
                    522:               //m_columnClasses.addElement(java.sql.Time.class);
                    523:             } else
                    524:               tableRow.add(null);
                    525:             m_columnClasses.addElement(String.class);
                    526:           } // to catch
                    527: 
                    528:         } else if (metaData.getColumnType(i) == Types.DATE)
                    529:         {
                    530:           // use the ResultSet.getObject method for retieving images
                    531:           // from FileMaker Pro container fields; the ResultSet.getObject
                    532:           // method returns a java.awt.Image object for FileMaker Pro
                    533:           // container fields
                    534: 
                    535:           tableRow.addElement(resultSet.getDate(i));
                    536:           m_columnClasses.addElement(java.sql.Date.class);
                    537:         } else if (metaData.getColumnTypeName(i) == "NUMBER")
                    538:         {
                    539:           // use the ResultSet.getObject method for retieving images
                    540:           // from FileMaker Pro container fields; the ResultSet.getObject
                    541:           // method returns a java.awt.Image object for FileMaker Pro
                    542:           // container fields
                    543:           try
                    544:           {
                    545:             tableRow.addElement(new Integer(resultSet.getInt(i)));
                    546:             m_columnClasses.addElement(Integer.class);
                    547: 
                    548:           } catch (Exception e)
                    549:           {
                    550: 
                    551:             StringBuffer number = new StringBuffer();
                    552:             String value = resultSet.getString(i);
                    553:             System.out.println(value);
                    554:             for (int c = 0; c < value.length(); ++c)
                    555:             {
                    556:               if (Character.isDigit(value.charAt(c)))
                    557:               {
                    558:                 number.append(value.charAt(c));
                    559:               }
                    560:             }
                    561:             if (number.length() > 0)
                    562:             {
                    563:               tableRow.addElement(null);
                    564:               m_columnClasses.addElement(Integer.class);
                    565:             } else
                    566:               tableRow.addElement(null);
                    567:           }
                    568:         } else
                    569:         {
                    570:           // all other field values are retrieved as strings and
                    571:           // added to the tableRow Vector
                    572:           // if(resultSet.getObject(i)!=null) System.out.println(resultSet.getObject(i));
                    573:           try
                    574:           {
                    575:             byte[] b = resultSet.getBytes(i);
                    576:             String utf8 = null;
                    577:             if (metaData instanceof ResultSetMetaDataExt)
                    578:               utf8 = (b == null) ? null : new String(b);
                    579:             else
                    580:               utf8 = (b == null) ? null : new String(b, "UTF-8");
                    581:             utf8 = (utf8 == null) ? null : new String(utf8.getBytes("UTF-8"), "UTF-8");
                    582:             tableRow.addElement(utf8);
                    583:           } catch (Exception e)
                    584:           {
                    585:             System.out.println("Hey I Got an error" + e);
                    586:           }
                    587:           m_columnClasses.addElement(java.lang.String.class);
                    588:         }
                    589:       }
                    590: 
                    591:       // add the tableRow Vector to the tableData Vector
                    592:       tableData.addElement(tableRow);
                    593:     }
                    594: 
                    595:     // retrieve the column names from the result set; the column names
                    596:     // are used for the table header
                    597:     columnNames = new Vector();
                    598: 
                    599:     for (int i = 1; i <= columnCount; i++)
                    600:       columnNames.addElement(metaData.getColumnName(i));
                    601:     Vector data[] = new Vector[2];
                    602:     data[0] = tableData;
                    603:     data[1] = columnNames;
                    604:     System.out.println("Rows " + tableData.size() + " " + ((Vector) tableData.get(0)).size());
                    605:     long timeEnd = System.currentTimeMillis();
                    606:     System.out.println("Time needed for query and data retrieval " + (timeEnd - timeStart) + " ms");
                    607:     return data;
                    608:   }
                    609: 
                    610:   public Vector getColumnNames()
                    611:   {
                    612:     if (result == null)
                    613:       return null;
                    614:     try
                    615:     {
                    616:       ResultSetMetaData metaData = result.getMetaData();
                    617:       int columnCount = metaData.getColumnCount();
                    618:       columnNames = new Vector();
                    619: 
                    620:       for (int i = 1; i <= columnCount; i++)
                    621:         columnNames.addElement(metaData.getColumnName(i));
                    622:     } catch (Exception e)
                    623:     {
                    624:     }
                    625:     return columnNames;
                    626:   }
                    627:   /**
                    628:    * makes the database Query
                    629:    *   with the numberOfHits as maximum
                    630:    * @return the result as an ResultSet object
                    631:   */
                    632:   public ResultSet makeQuery(String query, int numberOfHits) throws SQLException
                    633:   {
                    634:     result = null;
                    635:     Statement stm = null;
1.2     ! rogo      636:    
1.1       rogo      637:     //  System.out.println("Query " + query);
                    638: 
                    639:     if (!connection.isClosed())
                    640:       stm = connection.createStatement();
                    641:     stm.setMaxRows(numberOfHits);
1.2     ! rogo      642:     long time = System.currentTimeMillis();
        !           643:     stm.execute(query);
        !           644:     long time2 = System.currentTimeMillis();
        !           645:    
        !           646:     System.out.println("time to execute "+(time2-time));
        !           647:    // stm.setMaxRows(numberOfHits);
        !           648:  
        !           649:     result = stm.getResultSet();
        !           650:    // System.out.println(result+" "+stm.getUpdateCount());
1.1       rogo      651:     metaData = result.getMetaData();
                    652:     return result;
                    653:   }
                    654:   /**
                    655:    *  sets the database user
                    656:    */
                    657:   public void setUser(String user)
                    658:   {
                    659:     this.user = user;
                    660:   }
                    661:   /**
                    662:    *     sets the database passwd
                    663:    */
                    664:   public void setPasswd(String passwd)
                    665:   {
                    666:     this.passwd = passwd;
                    667:   }
                    668: 
                    669:   /**
                    670:    * sets the database user and passwd
                    671:    */
                    672:   public void setUserAndPasswd(String user, String passwd)
                    673:   {
                    674:     this.user = user;
                    675:     this.passwd = passwd;
                    676: 
                    677:   }
                    678:   /**
                    679:    *  just  sets the connection URL
                    680:    */
                    681:   public void setURL(String url)
                    682:   {
                    683:     this.url = url;
                    684:   }
                    685: 
                    686:   /**
                    687:    *    Test the database drivers features given by the DatabaseMetaData object
                    688:    */
                    689:   public Vector[] TestDB(DatabaseMetaData d) throws SQLException
                    690:   {
                    691: 
                    692:     Vector data[] = new Vector[2];
                    693:     Vector[] rows = new Vector[120];
                    694:     for (int i = 0; i < rows.length; ++i)
                    695:       rows[i] = new Vector();
                    696:     Vector columnNames = new Vector();
                    697:     columnNames.add("Feature");
                    698:     columnNames.add("Supported");
                    699: 
                    700:     Vector cols = new Vector();
                    701:     rows[0].add("allProceduresAreCallable");
                    702:     rows[0].add(new Boolean(d.allProceduresAreCallable()));
                    703:     //boolean allProceduresAreCallable() throws SQLException;
                    704:     rows[1].add("allTablesAreSelectable");
                    705:     rows[1].add(new Boolean(d.allTablesAreSelectable()));
                    706:     //    boolean allTablesAreSelectable() throws SQLException;
                    707:     rows[2].add("isReadOnly");
                    708:     rows[2].add(new Boolean(d.isReadOnly()));
                    709:     //    boolean isReadOnly() throws SQLException;
                    710:     rows[3].add("nullsAreSortedHigh");
                    711:     rows[3].add(new Boolean(d.nullsAreSortedHigh()));
                    712:     //    boolean nullsAreSortedHigh() throws SQLException;
                    713:     rows[4].add("nullsAreSortedLow");
                    714:     rows[4].add(new Boolean(d.nullsAreSortedLow()));
                    715:     // boolean nullsAreSortedLow() throws SQLException;
                    716:     rows[5].add("nullsAreSortedAtStart");
                    717:     rows[5].add(new Boolean(d.nullsAreSortedAtStart()));
                    718:     //  boolean nullsAreSortedAtStart() throws SQLException;
                    719:     rows[6].add("nullsAreSortedAtEnd");
                    720:     rows[6].add(new Boolean(d.nullsAreSortedAtEnd()));
                    721:     //  boolean nullsAreSortedAtEnd() throws SQLException;
                    722:     rows[7].add("usesLocalFiles");
                    723:     rows[7].add(new Boolean(d.usesLocalFiles()));
                    724:     //    boolean usesLocalFiles() throws SQLException;
                    725:     rows[8].add("usesLocalFilePerTable");
                    726:     rows[8].add(new Boolean(d.usesLocalFilePerTable()));
                    727:     // boolean usesLocalFilePerTable() throws SQLException;
                    728:     rows[9].add("supportsMixedCaseIdentifiers");
                    729:     rows[9].add(new Boolean(d.supportsMixedCaseIdentifiers()));
                    730:     //boolean supportsMixedCaseIdentifiers() throws SQLException;
                    731:     rows[10].add("storesUpperCaseIdentifiers");
                    732:     rows[10].add(new Boolean(d.storesUpperCaseIdentifiers()));
                    733:     // boolean storesUpperCaseIdentifiers() throws SQLException;
                    734:     rows[11].add("storesLowerCaseIdentifiers");
                    735:     rows[11].add(new Boolean(d.storesLowerCaseIdentifiers()));
                    736:     //    boolean storesLowerCaseIdentifiers() throws SQLException;
                    737:     rows[12].add("storesMixedCaseIdentifiers");
                    738:     rows[12].add(new Boolean(d.storesMixedCaseIdentifiers()));
                    739:     //    boolean storesMixedCaseIdentifiers() throws SQLException;
                    740:     rows[13].add("supportsMixedCaseQuotedIdentifiers");
                    741:     rows[13].add(new Boolean(d.supportsMixedCaseQuotedIdentifiers()));
                    742:     //    boolean supportsMixedCaseQuotedIdentifiers() throws SQLException;
                    743:     rows[14].add("storesUpperCaseQuotedIdentifiers");
                    744:     rows[14].add(new Boolean(d.storesUpperCaseQuotedIdentifiers()));
                    745:     //   boolean storesUpperCaseQuotedIdentifiers() throws SQLException;
                    746:     rows[15].add("storesLowerCaseQuotedIdentifiers");
                    747:     rows[15].add(new Boolean(d.storesLowerCaseQuotedIdentifiers()));
                    748:     //boolean storesLowerCaseQuotedIdentifiers() throws SQLException;
                    749:     rows[16].add("storesMixedCaseQuotedIdentifiers");
                    750:     rows[16].add(new Boolean(d.storesMixedCaseQuotedIdentifiers()));
                    751:     // boolean storesMixedCaseQuotedIdentifiers() throws SQLException;
                    752:     rows[17].add("supportsAlterTableWithAddColumn");
                    753:     rows[17].add(new Boolean(d.supportsAlterTableWithAddColumn()));
                    754:     //    boolean supportsAlterTableWithAddColumn() throws SQLException;
                    755:     rows[18].add("supportsAlterTableWithDropColumn");
                    756:     rows[18].add(new Boolean(d.supportsAlterTableWithDropColumn()));
                    757:     //  boolean supportsAlterTableWithDropColumn() throws SQLException;
                    758:     rows[19].add("nullPlusNonNullIsNull");
                    759:     rows[19].add(new Boolean(d.nullPlusNonNullIsNull()));
                    760:     //   boolean nullPlusNonNullIsNull() throws SQLException;
                    761:     rows[20].add("supportsConvert");
                    762:     rows[20].add(new Boolean(d.supportsConvert()));
                    763:     // boolean supportsConvert() throws SQLException;
                    764: 
                    765:     // boolean supportsConvert(int fromType, int toType) throws SQLException;
                    766:     rows[21].add("supportsTableCorrelationNames");
                    767:     rows[21].add(new Boolean(d.supportsTableCorrelationNames()));
                    768:     //  boolean supportsTableCorrelationNames() throws SQLException;
                    769:     rows[22].add("supportsDifferentTableCorrelationNames");
                    770:     rows[22].add(new Boolean(d.supportsDifferentTableCorrelationNames()));
                    771:     // boolean supportsDifferentTableCorrelationNames() throws SQLException;
                    772:     rows[23].add("supportsExpressionsInOrderBy");
                    773:     rows[23].add(new Boolean(d.supportsExpressionsInOrderBy()));
                    774:     // boolean supportsExpressionsInOrderBy() throws SQLException;
                    775:     rows[24].add("supportsOrderByUnrelated");
                    776:     rows[24].add(new Boolean(d.supportsOrderByUnrelated()));
                    777:     //   boolean supportsOrderByUnrelated() throws SQLException;
                    778:     rows[25].add("supportsGroupBy");
                    779:     rows[25].add(new Boolean(d.supportsGroupBy()));
                    780:     //  boolean supportsGroupBy() throws SQLException;
                    781:     rows[26].add("supportsGroupByUnrelated");
                    782:     rows[26].add(new Boolean(d.supportsGroupByUnrelated()));
                    783:     // boolean supportsGroupByUnrelated() throws SQLException;
                    784:     rows[27].add("supportsGroupByBeyondSelect");
                    785:     rows[27].add(new Boolean(d.supportsGroupByBeyondSelect()));
                    786:     //  boolean supportsGroupByBeyondSelect() throws SQLException;
                    787:     rows[28].add("supportsLikeEscapeClause");
                    788:     rows[28].add(new Boolean(d.supportsLikeEscapeClause()));
                    789:     // boolean supportsLikeEscapeClause() throws SQLException;
                    790:     rows[29].add("supportsMultipleResultSets");
                    791:     rows[29].add(new Boolean(d.supportsMultipleResultSets()));
                    792:     // boolean supportsMultipleResultSets() throws SQLException;
                    793:     rows[30].add("supportsMultipleTransactions");
                    794:     rows[30].add(new Boolean(d.supportsMultipleTransactions()));
                    795:     //  boolean supportsMultipleTransactions() throws SQLException;
                    796:     rows[31].add("supportsNonNullableColumns");
                    797:     rows[31].add(new Boolean(d.supportsNonNullableColumns()));
                    798:     //    boolean supportsNonNullableColumns() throws SQLException;
                    799:     rows[32].add("supportsMinimumSQLGrammar");
                    800:     rows[32].add(new Boolean(d.supportsMinimumSQLGrammar()));
                    801:     // boolean supportsMinimumSQLGrammar() throws SQLException;
                    802:     rows[33].add("supportsCoreSQLGrammar");
                    803:     rows[33].add(new Boolean(d.supportsCoreSQLGrammar()));
                    804:     // boolean supportsCoreSQLGrammar() throws SQLException;
                    805:     rows[34].add("supportsExtendedSQLGrammar");
                    806:     rows[34].add(new Boolean(d.supportsExtendedSQLGrammar()));
                    807:     // boolean supportsExtendedSQLGrammar() throws SQLException;
                    808:     rows[35].add("supportsANSI92EntryLevelSQL");
                    809:     rows[35].add(new Boolean(d.supportsANSI92EntryLevelSQL()));
                    810:     // boolean supportsANSI92EntryLevelSQL() throws SQLException;
                    811:     rows[36].add("supportsANSI92IntermediateSQL");
                    812:     rows[36].add(new Boolean(d.supportsANSI92IntermediateSQL()));
                    813:     //boolean supportsANSI92IntermediateSQL() throws SQLException;
                    814:     rows[37].add("supportsANSI92FullSQL");
                    815:     rows[37].add(new Boolean(d.supportsANSI92FullSQL()));
                    816:     //boolean supportsANSI92FullSQL() throws SQLException;
                    817:     rows[38].add("supportsIntegrityEnhancementFacility");
                    818:     rows[38].add(new Boolean(d.supportsIntegrityEnhancementFacility()));
                    819:     //boolean supportsIntegrityEnhancementFacility() throws SQLException;
                    820:     rows[39].add("supportsOuterJoins");
                    821:     rows[39].add(new Boolean(d.supportsOuterJoins()));
                    822:     //boolean supportsOuterJoins() throws SQLException;
                    823:     rows[40].add("supportsFullOuterJoins");
                    824:     rows[40].add(new Boolean(d.supportsFullOuterJoins()));
                    825:     //boolean supportsFullOuterJoins() throws SQLException;
                    826:     rows[41].add("supportsLimitedOuterJoins");
                    827:     rows[41].add(new Boolean(d.supportsLimitedOuterJoins()));
                    828:     //boolean supportsLimitedOuterJoins() throws SQLException;
                    829:     rows[42].add("isCatalogAtStart");
                    830:     rows[42].add(new Boolean(d.isCatalogAtStart()));
                    831:     //boolean isCatalogAtStart() throws SQLException;
                    832:     rows[43].add("supportsSchemasInDataManipulation");
                    833:     rows[43].add(new Boolean(d.supportsSchemasInDataManipulation()));
                    834:     //boolean supportsSchemasInDataManipulation() throws SQLException;
                    835:     rows[44].add("supportsSchemasInProcedureCalls");
                    836:     rows[44].add(new Boolean(d.supportsSchemasInProcedureCalls()));
                    837:     //boolean supportsSchemasInProcedureCalls() throws SQLException;
                    838:     rows[45].add("supportsSchemasInTableDefinitions");
                    839:     rows[45].add(new Boolean(d.supportsSchemasInTableDefinitions()));
                    840:     //boolean supportsSchemasInTableDefinitions() throws SQLException;
                    841:     rows[46].add("supportsSchemasInIndexDefinitions");
                    842:     rows[46].add(new Boolean(d.supportsSchemasInIndexDefinitions()));
                    843:     //boolean supportsSchemasInIndexDefinitions() throws SQLException;
                    844:     rows[47].add("supportsSchemasInPrivilegeDefinitions");
                    845:     rows[47].add(new Boolean(d.supportsSchemasInPrivilegeDefinitions()));
                    846:     //boolean supportsSchemasInPrivilegeDefinitions() throws SQLException;
                    847:     rows[48].add("supportsCatalogsInDataManipulation");
                    848:     rows[48].add(new Boolean(d.supportsCatalogsInDataManipulation()));
                    849:     //boolean supportsCatalogsInDataManipulation() throws SQLException;
                    850:     rows[49].add("supportsCatalogsInProcedureCalls");
                    851:     rows[49].add(new Boolean(d.supportsCatalogsInProcedureCalls()));
                    852:     //boolean supportsCatalogsInProcedureCalls() throws SQLException;
                    853:     rows[50].add("supportsCatalogsInTableDefinitions");
                    854:     rows[50].add(new Boolean(d.supportsCatalogsInTableDefinitions()));
                    855:     //boolean supportsCatalogsInTableDefinitions() throws SQLException;
                    856:     rows[51].add("supportsCatalogsInIndexDefinitions");
                    857:     rows[51].add(new Boolean(d.supportsCatalogsInIndexDefinitions()));
                    858:     //boolean supportsCatalogsInIndexDefinitions() throws SQLException;
                    859:     rows[52].add("supportsCatalogsInPrivilegeDefinitions");
                    860:     rows[52].add(new Boolean(d.supportsCatalogsInPrivilegeDefinitions()));
                    861:     //boolean supportsCatalogsInPrivilegeDefinitions() throws SQLException;
                    862:     rows[53].add("supportsPositionedDelete");
                    863:     rows[53].add(new Boolean(d.supportsPositionedDelete()));
                    864:     //boolean supportsPositionedDelete() throws SQLException;
                    865:     rows[54].add("supportsPositionedUpdate");
                    866:     rows[54].add(new Boolean(d.supportsPositionedUpdate()));
                    867:     //boolean supportsPositionedUpdate() throws SQLException;
                    868:     rows[55].add("supportsSelectForUpdate");
                    869:     rows[55].add(new Boolean(d.supportsSelectForUpdate()));
                    870:     //boolean supportsSelectForUpdate() throws SQLException;
                    871:     rows[56].add("supportsStoredProcedures");
                    872:     rows[56].add(new Boolean(d.supportsStoredProcedures()));
                    873:     //boolean supportsStoredProcedures() throws SQLException;
                    874:     rows[57].add("supportsSubqueriesInComparisons");
                    875:     rows[57].add(new Boolean(d.supportsSubqueriesInComparisons()));
                    876:     //boolean supportsSubqueriesInComparisons() throws SQLException;
                    877:     rows[58].add("supportsSubqueriesInExists");
                    878:     rows[58].add(new Boolean(d.supportsSubqueriesInExists()));
                    879:     //boolean supportsSubqueriesInExists() throws SQLException;
                    880:     rows[59].add("supportsSubqueriesInIns");
                    881:     rows[59].add(new Boolean(d.supportsSubqueriesInIns()));
                    882:     //boolean supportsSubqueriesInIns() throws SQLException;
                    883:     rows[60].add("supportsSubqueriesInQuantifieds");
                    884:     rows[60].add(new Boolean(d.supportsSubqueriesInQuantifieds()));
                    885:     //boolean supportsSubqueriesInQuantifieds() throws SQLException;
                    886:     rows[61].add("supportsCorrelatedSubqueries");
                    887:     rows[61].add(new Boolean(d.supportsCorrelatedSubqueries()));
                    888:     //boolean supportsCorrelatedSubqueries() throws SQLException;
                    889:     rows[62].add("supportsUnion");
                    890:     rows[62].add(new Boolean(d.supportsUnion()));
                    891:     //boolean supportsUnion() throws SQLException;
                    892:     rows[63].add("supportsUnionAll");
                    893:     rows[63].add(new Boolean(d.supportsUnionAll()));
                    894:     //boolean supportsUnionAll() throws SQLException;
                    895:     rows[64].add("supportsOpenCursorsAcrossCommit");
                    896:     rows[64].add(new Boolean(d.supportsOpenCursorsAcrossCommit()));
                    897:     //boolean supportsOpenCursorsAcrossCommit() throws SQLException;
                    898:     rows[65].add("supportsOpenCursorsAcrossRollback");
                    899:     rows[65].add(new Boolean(d.supportsOpenCursorsAcrossRollback()));
                    900:     //boolean supportsOpenCursorsAcrossRollback() throws SQLException;
                    901:     rows[66].add("supportsOpenStatementsAcrossCommit");
                    902:     rows[66].add(new Boolean(d.supportsOpenStatementsAcrossCommit()));
                    903:     //boolean supportsOpenStatementsAcrossCommit() throws SQLException;
                    904:     rows[67].add("supportsOpenStatementsAcrossRollback");
                    905:     rows[67].add(new Boolean(d.supportsOpenStatementsAcrossRollback()));
                    906:     //boolean supportsOpenStatementsAcrossRollback() throws SQLException;
                    907:     rows[68].add("doesMaxRowSizeIncludeBlobs");
                    908:     rows[68].add(new Boolean(d.doesMaxRowSizeIncludeBlobs()));
                    909:     //boolean doesMaxRowSizeIncludeBlobs() throws SQLException;
                    910:     rows[69].add("supportsTransactions");
                    911:     rows[69].add(new Boolean(d.supportsTransactions()));
                    912:     //boolean supportsTransactions() throws SQLException;
                    913:     rows[70].add("supportsTransactionIsolationLevel");
                    914:     rows[70].add(new Boolean(d.supportsTransactionIsolationLevel(1)));
                    915:     //boolean supportsTransactionIsolationLevel(int level) throws SQLException;
                    916:     rows[71].add("supportsDataDefinitionAndDataManipulationTransactions");
                    917:     rows[71].add(new Boolean(d.supportsDataDefinitionAndDataManipulationTransactions()));
                    918:     //boolean supportsDataDefinitionAndDataManipulationTransactions() throws SQLException;
                    919:     rows[72].add("supportsDataManipulationTransactionsOnly");
                    920:     rows[72].add(new Boolean(d.supportsDataManipulationTransactionsOnly()));
                    921:     //boolean supportsDataManipulationTransactionsOnly() throws SQLException;
                    922:     rows[73].add("dataDefinitionCausesTransactionCommit");
                    923:     rows[73].add(new Boolean(d.dataDefinitionCausesTransactionCommit()));
                    924:     //boolean dataDefinitionCausesTransactionCommit() throws SQLException;
                    925:     rows[74].add("dataDefinitionIgnoredInTransactions");
                    926:     rows[74].add(new Boolean(d.dataDefinitionIgnoredInTransactions()));
                    927:     //boolean dataDefinitionIgnoredInTransactions() throws SQLException;
                    928:     rows[75].add("getMaxBinaryLiteralLength");
                    929:     rows[75].add(new Integer(d.getMaxBinaryLiteralLength()));
                    930:     // int getMaxBinaryLiteralLength() throws SQLException;
                    931:     rows[76].add("getMaxCharLiteralLength");
                    932:     rows[76].add(new Integer(d.getMaxCharLiteralLength()));
                    933:     //int getMaxCharLiteralLength() throws SQLException;
                    934:     rows[77].add("getMaxColumnNameLength");
                    935:     rows[77].add(new Integer(d.getMaxColumnNameLength()));
                    936:     // int getMaxColumnNameLength() throws SQLException;
                    937:     rows[78].add("getMaxColumnsInGroupBy");
                    938:     rows[78].add(new Integer(d.getMaxColumnsInGroupBy()));
                    939:     //int getMaxColumnsInGroupBy() throws SQLException;
                    940:     rows[79].add("getMaxColumnsInIndex");
                    941:     rows[79].add(new Integer(d.getMaxColumnsInIndex()));
                    942:     //int getMaxColumnsInIndex() throws SQLException;
                    943:     rows[80].add("getMaxColumnsInOrderBy");
                    944:     rows[80].add(new Integer(d.getMaxColumnsInOrderBy()));
                    945:     //int getMaxColumnsInOrderBy() throws SQLException;
                    946:     rows[81].add("getMaxColumnsInSelect");
                    947:     rows[81].add(new Integer(d.getMaxColumnsInSelect()));
                    948:     //int getMaxColumnsInSelect() throws SQLException;
                    949:     rows[82].add("getMaxColumnsInTable");
                    950:     rows[82].add(new Integer(d.getMaxColumnsInTable()));
                    951:     //int getMaxColumnsInTable() throws SQLException;
                    952:     rows[83].add("getMaxConnections");
                    953:     rows[83].add(new Integer(d.getMaxConnections()));
                    954:     //int getMaxConnections() throws SQLException;
                    955:     rows[84].add("getMaxCursorNameLength");
                    956:     rows[84].add(new Integer(d.getMaxCursorNameLength()));
                    957:     //    int getMaxCursorNameLength() throws SQLException;
                    958:     rows[85].add("getMaxIndexLength");
                    959:     rows[85].add(new Integer(d.getMaxIndexLength()));
                    960:     //int getMaxIndexLength() throws SQLException;
                    961:     rows[86].add("getMaxSchemaNameLength");
                    962:     rows[86].add(new Integer(d.getMaxSchemaNameLength()));
                    963:     //int getMaxSchemaNameLength() throws SQLException;
                    964:     rows[87].add("getMaxProcedureNameLength");
                    965:     rows[87].add(new Integer(d.getMaxProcedureNameLength()));
                    966:     //int getMaxProcedureNameLength() throws SQLException;
                    967:     rows[88].add("getMaxCatalogNameLength");
                    968:     rows[88].add(new Integer(d.getMaxCatalogNameLength()));
                    969:     //int getMaxCatalogNameLength() throws SQLException;
                    970:     rows[89].add("getMaxRowSize");
                    971:     rows[89].add(new Integer(d.getMaxRowSize()));
                    972:     //int getMaxRowSize() throws SQLException;
                    973:     rows[90].add("getMaxStatementLength");
                    974:     rows[90].add(new Integer(d.getMaxStatementLength()));
                    975:     //int getMaxStatementLength() throws SQLException;
                    976:     rows[91].add("getMaxStatements");
                    977:     rows[91].add(new Integer(d.getMaxStatements()));
                    978:     //int getMaxStatements() throws SQLException;
                    979:     rows[92].add("getMaxTableNameLength");
                    980:     rows[92].add(new Integer(d.getMaxTableNameLength()));
                    981:     //int getMaxTableNameLength() throws SQLException;
                    982:     rows[93].add("getMaxTablesInSelect");
                    983:     rows[93].add(new Integer(d.getMaxTablesInSelect()));
                    984:     //int getMaxTablesInSelect() throws SQLException;
                    985:     rows[94].add("getMaxUserNameLength");
                    986:     rows[94].add(new Integer(d.getMaxUserNameLength()));
                    987:     // int getMaxUserNameLength() throws SQLException;
                    988:     rows[95].add("getDefaultTransactionIsolation");
                    989:     rows[95].add(new Integer(d.getDefaultTransactionIsolation()));
                    990:     //int getDefaultTransactionIsolation() throws SQLException;
                    991: 
                    992:     rows[96].add("getDatabaseProductName");
                    993:     rows[96].add(d.getDatabaseProductName());
                    994:     // String getDatabaseProductName() throws SQLException;
                    995:     rows[97].add("getDatabaseProductVersion");
                    996:     rows[97].add(d.getDatabaseProductVersion());
                    997:     //String getDatabaseProductVersion() throws SQLException;
                    998: 
                    999:     rows[98].add("getURL");
                   1000:     rows[98].add(d.getURL());
                   1001:     //String getURL() throws SQLException;
                   1002:     rows[99].add("getUserName");
                   1003:     rows[99].add(d.getUserName());
                   1004:     //String getUserName() throws SQLException;
                   1005:     rows[100].add("getDriverName");
                   1006:     rows[100].add(d.getDriverName());
                   1007:     //    String getDriverName() throws SQLException;
                   1008:     rows[101].add("getIdentifierQuoteString");
                   1009:     rows[101].add(d.getIdentifierQuoteString());
                   1010:     //String getIdentifierQuoteString() throws SQLException;
                   1011: 
                   1012:     rows[102].add("getDriverVersion");
                   1013:     rows[102].add(d.getDriverVersion());
                   1014:     //String getDriverVersion() throws SQLException;
                   1015:     rows[103].add("getDriverMajorVersion");
                   1016:     rows[103].add(new Integer(d.getDriverMajorVersion()));
                   1017:     //int getDriverMajorVersion();
                   1018:     rows[104].add("getDriverMinorVersion");
                   1019:     rows[104].add(new Integer(d.getDriverMinorVersion()));
                   1020:     //int getDriverMinorVersion();
                   1021:     rows[105].add("getSQLKeywords");
                   1022:     rows[105].add(d.getSQLKeywords());
                   1023:     //String getSQLKeywords() throws SQLException;
                   1024:     rows[106].add("getNumericFunctions");
                   1025:     rows[106].add(d.getNumericFunctions());
                   1026:     //String getNumericFunctions() throws SQLException;
                   1027:     rows[107].add("getStringFunctions");
                   1028:     rows[107].add(d.getStringFunctions());
                   1029:     // String getStringFunctions() throws SQLException;
                   1030:     rows[108].add("getSystemFunctions");
                   1031:     rows[108].add(d.getSystemFunctions());
                   1032:     //String getSystemFunctions() throws SQLException;
                   1033:     rows[109].add("getTimeDateFunctions");
                   1034:     rows[109].add(d.getTimeDateFunctions());
                   1035:     //String getTimeDateFunctions() throws SQLException;
                   1036:     rows[110].add("getSearchStringEscape");
                   1037:     rows[110].add(d.getSearchStringEscape());
                   1038:     //String getSearchStringEscape() throws SQLException;
                   1039:     rows[111].add("getExtraNameCharacters");
                   1040:     rows[111].add(d.getExtraNameCharacters());
                   1041:     //String getExtraNameCharacters() throws SQLException;
                   1042:     rows[112].add("getSchemaTerm");
                   1043:     rows[112].add(d.getSchemaTerm());
                   1044:     //String getSchemaTerm() throws SQLException;
                   1045:     rows[113].add("getProcedureTerm");
                   1046:     rows[113].add(d.getProcedureTerm());
                   1047:     //String getProcedureTerm() throws SQLException;
                   1048:     rows[114].add("getCatalogTerm");
                   1049:     rows[114].add(d.getCatalogTerm());
                   1050:     // String getCatalogTerm() throws SQLException;
                   1051:     rows[115].add("getCatalogSeparator");
                   1052:     rows[115].add(d.getCatalogSeparator());
                   1053:     //String getCatalogSeparator() throws SQLException;
                   1054: 
                   1055:     /*
                   1056:      boolean supportsResultSetType(int type) throws SQLException;
                   1057:     
                   1058:      boolean supportsResultSetConcurrency(int type, int concurrency) throws SQLException;
                   1059:     
                   1060:      boolean ownUpdatesAreVisible(int type) throws SQLException;
                   1061:     
                   1062:      boolean ownDeletesAreVisible(int type) throws SQLException;
                   1063:     
                   1064:      boolean ownInsertsAreVisible(int type) throws SQLException;
                   1065:     
                   1066:      boolean othersUpdatesAreVisible(int type) throws SQLException;
                   1067:     
                   1068:      boolean othersDeletesAreVisible(int type) throws SQLException;
                   1069:     
                   1070:      boolean othersInsertsAreVisible(int type) throws SQLException;
                   1071:      boolean updatesAreDetected(int type) throws SQLException;
                   1072:      boolean deletesAreDetected(int type) throws SQLException;
                   1073:     
                   1074:      boolean insertsAreDetected(int type) throws SQLException;
                   1075:     */
                   1076:     // not in filemaker
                   1077:     // rows[96].add("supportsBatchUpdates");
                   1078:     // rows[96].add(new Boolean(d.supportsBatchUpdates()));
                   1079:     //boolean supportsBatchUpdates() throws SQLException;
                   1080: 
                   1081:     /*
                   1082:     ResultSet getProcedures(String catalog, String schemaPattern, String procedureNamePattern) throws SQLException;
                   1083:     
                   1084:     ResultSet getProcedureColumns(String catalog, String schemaPattern, String procedureNamePattern, String columnNamePattern) throws SQLException;
                   1085:     ResultSet getTables(String catalog, String schemaPattern, String tableNamePattern, String types[]) throws SQLException;
                   1086:     ResultSet getSchemas() throws SQLException;
                   1087:     ResultSet getCatalogs() throws SQLException;
                   1088:     ResultSet getTableTypes() throws SQLException;
                   1089:     ResultSet getColumns(String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern) throws SQLException;
                   1090:     ResultSet getPrimaryKeys(String catalog, String schema, String table) throws SQLException;
                   1091:     ResultSet getImportedKeys(String catalog, String schema, String table) throws SQLException;
                   1092:     ResultSet getExportedKeys(String catalog, String schema, String table) throws SQLException;
                   1093:     ResultSet getCrossReference(String primaryCatalog, String primarySchema, String primaryTable, String foreignCatalog, String foreignSchema, String foreignTable) throws SQLException;
                   1094:     ResultSet getTypeInfo() throws SQLException;
                   1095:     ResultSet getIndexInfo(String catalog, String schema, String table, boolean unique, boolean approximate) throws SQLException;
                   1096:     
                   1097:     ResultSet getUDTs(String catalog, String schemaPattern, String typeNamePattern, int[] types) throws SQLException;
                   1098:     
                   1099:     Connection getConnection() throws SQLException;
                   1100:     
                   1101:     */
                   1102:     for (int i = 0; i < rows.length; ++i)
                   1103:       cols.add(rows[i]);
                   1104:     data[0] = cols;
                   1105:     data[1] = columnNames;
                   1106:     return data;
                   1107:   }
                   1108:   public Vector getNextRow() throws Exception
                   1109:   {
                   1110: 
                   1111:     if (result == null)
                   1112:       return null;
                   1113:     boolean check = false;
                   1114:     ResultSet resultSet = result;
                   1115:     ResultSetMetaData metaData = resultSet.getMetaData();
                   1116:     int columnCount = metaData.getColumnCount();
                   1117:     Vector tableData = new Vector();
                   1118:     check = resultSet.next();
                   1119:     //  System.out.println("hallo check "+check);
                   1120:     if (!check)
                   1121:       return null;
                   1122:     Vector tableRow = new Vector(), m_columnClasses = new Vector();
                   1123:     for (int i = 1; i <= columnCount; i++)
                   1124:     {
                   1125:       // repeating fields and fields from related databases may contain
                   1126:       // multliple data values; the data values are stored using
                   1127:       // a Vector which is then added to the tableRow
                   1128:       //      if (metaData instanceof ResultSetMetaDataExt)
                   1129:       if ((metaData instanceof ResultSetMetaDataExt) && (((ResultSetMetaDataExt) metaData).isRelated(i) || ((ResultSetMetaDataExt) metaData).isRepeating(i)))
                   1130:       {
                   1131:         //System.out.println("Related fields");
                   1132:         // retrieve the repeating or related field contents as a
                   1133:         // com.fmi.jdbc.Array via the ResultSet.getObject method
                   1134:         com.fmi.jdbc.Array array = (com.fmi.jdbc.Array) resultSet.getObject(i);
                   1135:         //            create a Vector for storing all of the data values
                   1136:         ArrayList columnData = new ArrayList();
                   1137:         try
                   1138:         {
                   1139: 
                   1140:           // call the Array.getStringArray method since the data will
                   1141:           // only be displayed
                   1142:           Object[] fieldData = (Object[]) array.getArray();
                   1143: 
                   1144:           if (fieldData != null)
                   1145:           {
                   1146:             // add each value to the Vector
                   1147:             for (int j = 0; j < fieldData.length; j++)
                   1148:             {
                   1149:               if (fieldData[j] != null)
                   1150:                 columnData.add(fieldData[j]);
                   1151:             }
                   1152:           }
                   1153:         } catch (Exception e)
                   1154:         {
                   1155:           //System.out.println(e);
                   1156:         }
                   1157: 
                   1158:         if (columnData.isEmpty())
                   1159:           tableRow.add(null);
                   1160:         else
                   1161:           tableRow.addElement(columnData);
                   1162:         //System.out.println(columnData);
                   1163:         //System.out.println("Related fields"+columnData.size()+" "+tableRow.size());
                   1164: 
                   1165:         // m_columnClasses.addElement(java.util.Vector.class);
                   1166:       } else if (metaData.getColumnType(i) == Types.LONGVARBINARY)
                   1167:       {
                   1168:         // use the ResultSet.getObject method for retrieving images
                   1169:         // from FileMaker Pro container fields; the ResultSet.getObject
                   1170:         // method returns a java.awt.Image object for FileMaker Pro
                   1171:         // container fields
                   1172: 
                   1173:         try
                   1174:         {
                   1175:           tableRow.addElement(resultSet.getObject(i));
                   1176:         } catch (Exception e)
                   1177:         {
                   1178:           // TODO Auto-generated catch block
                   1179:           // e.printStackTrace();
                   1180:           tableRow.addElement(null);
                   1181:         }
                   1182:         //    m_columnClasses.addElement(java.awt.Image.class);
                   1183:       } else if (metaData.getColumnType(i) == Types.TIME)
                   1184:       {
                   1185:         // use the ResultSet.getObject method for retieving images
                   1186:         // from FileMaker Pro container fields; the ResultSet.getObject
                   1187:         // method returns a java.awt.Image object for FileMaker Pro
                   1188:         // container fields
                   1189:         try
                   1190:         {
                   1191:           tableRow.addElement(resultSet.getTime(i).toString());
                   1192:           //    m_columnClasses.addElement(java.sql.Time.class);
                   1193:         } catch (Exception e)
                   1194:         {
                   1195: 
                   1196:           String value = resultSet.getString(i);
                   1197:           if (value != null)
                   1198:           {
                   1199:             //System.out.println("SQLTime new "+Time.valueOf("17:00:00").toString());
                   1200:             int index = 0;
                   1201:             for (int j = 0; j < value.length(); ++j)
                   1202:             {
                   1203:               if (!Character.isLetter(value.charAt(j)))
                   1204:                 index = j + 1;
                   1205:               else
                   1206:                 break;
                   1207:             }
                   1208: 
                   1209:             tableRow.addElement(value.substring(0, index));
                   1210:             //m_columnClasses.addElement(java.sql.Time.class);
                   1211:           } else
                   1212:             tableRow.add(null);
                   1213:           //  m_columnClasses.addElement(String.class);
                   1214:         } // to catch
                   1215: 
                   1216:       } else if (metaData.getColumnType(i) == Types.DATE)
                   1217:       {
                   1218:         // use the ResultSet.getObject method for retieving images
                   1219:         // from FileMaker Pro container fields; the ResultSet.getObject
                   1220:         // method returns a java.awt.Image object for FileMaker Pro
                   1221:         // container fields
                   1222: 
                   1223:         tableRow.addElement(resultSet.getDate(i));
                   1224:         //  m_columnClasses.addElement(java.sql.Date.class);
                   1225:       } else if (metaData.getColumnTypeName(i) == "NUMBER")
                   1226:       {
                   1227:         // use the ResultSet.getObject method for retieving images
                   1228:         // from FileMaker Pro container fields; the ResultSet.getObject
                   1229:         // method returns a java.awt.Image object for FileMaker Pro
                   1230:         // container fields
                   1231:         try
                   1232:         {
                   1233:           tableRow.addElement(new Integer(resultSet.getInt(i)));
                   1234:           // m_columnClasses.addElement(Integer.class);
                   1235: 
                   1236:         } catch (Exception e)
                   1237:         {
                   1238: 
                   1239:           StringBuffer number = new StringBuffer();
                   1240:           String value = resultSet.getString(i);
                   1241:           System.out.println(value);
                   1242:           for (int c = 0; c < value.length(); ++c)
                   1243:           {
                   1244:             if (Character.isDigit(value.charAt(c)))
                   1245:             {
                   1246:               number.append(value.charAt(c));
                   1247:             }
                   1248:           }
                   1249:           if (number.length() > 0)
                   1250:           {
                   1251:             tableRow.addElement(null);
                   1252:             //   m_columnClasses.addElement(Integer.class);
                   1253:           } else
                   1254:             tableRow.addElement(null);
                   1255:         }
                   1256:       } else
                   1257:       {
                   1258:         // all other field values are retrieved as strings and
                   1259:         // added to the tableRow Vector
                   1260:         //   System.out.println("row "+resultSet.getString(i));
                   1261:         try
                   1262:         {
                   1263:           byte[] b = null;
                   1264:           if (metaData instanceof ResultSetMetaDataExt)
                   1265:             b = resultSet.getBytes(i);
                   1266:           String utf8 = null;
                   1267:           utf8 = (b == null) ? null : new String(b);
                   1268:           if (metaData instanceof ResultSetMetaDataExt)
                   1269:             tableRow.addElement((b != null) ? new String(utf8.getBytes()) : null);
                   1270:           else
                   1271:           {
                   1272:             //  byte[] val = resultSet.getBytes(i);
                   1273:             tableRow.add(resultSet.getString(i));
                   1274:             //tableRow.addElement((val==null) ? null:new String(val,"UTF-8"));
                   1275:           }
                   1276:         } catch (Exception e)
                   1277:         {
                   1278:           System.out.println("Hey I Got an error" + e);
                   1279:           e.printStackTrace();
                   1280:         }
                   1281:         // m_columnClasses.addElement(java.lang.String.class);
                   1282:       }
                   1283:     }
                   1284:     //  tableData.addElement(tableRow);
                   1285:     if (check)
                   1286:       return tableRow;
                   1287:     else
                   1288:       return null;
                   1289:   }
                   1290:   class ConnectionPool
                   1291:   {
                   1292:     String user = "", passwd = "", url = "";
                   1293:     Connection con;
                   1294:     public ConnectionPool(String url, String user, String passwd, Connection con)
                   1295:     {
                   1296:       this.con = con;
                   1297:       this.user = user;
                   1298:       this.passwd = passwd;
                   1299:       this.url = url;
                   1300:     }
                   1301: 
                   1302:   }
                   1303:   public String getQC()
                   1304:   {
                   1305:     // if (connection == null)
                   1306:     // return "";
                   1307: 
                   1308:     // check if connection null if null try to get one
                   1309:     if (connection == null)
                   1310:       try
                   1311:       {
                   1312:         getConnection();
                   1313:       } catch (Exception e)
                   1314:       {
                   1315:         if (FM2SQL.debug)
                   1316:           System.out.println("cannot get a connection");
                   1317:       }
                   1318:     if (connection == null)
                   1319:     {
                   1320:       if (url.toLowerCase().indexOf("fmpro") >= 0 || url.toLowerCase().indexOf("postgres") >= 0)
                   1321:         quoteChar = "\"";
                   1322:       else if (url.toLowerCase().indexOf("mysql") >= 0)
                   1323:         quoteChar = "`";
                   1324:     }
                   1325:     if (quoteChar == null)
                   1326:       quoteChar = "\""; // needed for postgres
                   1327:     return quoteChar;
                   1328:   }
                   1329:   public int getRowCount(String query) throws SQLException
                   1330:   {
                   1331:     String table = query.substring(query.indexOf("from") + 4).trim();
                   1332:     int index = table.indexOf(" ");
                   1333:     table = table.substring(0, (index >= 0) ? index : table.length());
                   1334:     System.out.println(table);
                   1335:     Statement stm = null;
                   1336: 
                   1337:     if (metaData instanceof ResultSetMetaDataExt)
                   1338:       return 1000;
                   1339:     if (!connection.isClosed())
                   1340:       stm = connection.createStatement();
                   1341:     stm.setMaxRows(1);
                   1342:     ResultSet resultSet = stm.executeQuery("select count(*) from " + table);
                   1343:     resultSet.next();
                   1344:     return resultSet.getInt(1);
                   1345:   }
                   1346: 
                   1347: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>