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