Annotation of FM2SQL/DBBean.java, revision 1.1.1.1
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<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: 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;
636: // System.out.println("Query " + query);
637:
638: if (!connection.isClosed())
639: stm = connection.createStatement();
640: stm.setMaxRows(numberOfHits);
641: result = stm.executeQuery(query);
642: // System.out.println(result+" "+stm.getMoreResults());
643: metaData = result.getMetaData();
644: return result;
645: }
646: /**
647: * sets the database user
648: */
649: public void setUser(String user)
650: {
651: this.user = user;
652: }
653: /**
654: * sets the database passwd
655: */
656: public void setPasswd(String passwd)
657: {
658: this.passwd = passwd;
659: }
660:
661: /**
662: * sets the database user and passwd
663: */
664: public void setUserAndPasswd(String user, String passwd)
665: {
666: this.user = user;
667: this.passwd = passwd;
668:
669: }
670: /**
671: * just sets the connection URL
672: */
673: public void setURL(String url)
674: {
675: this.url = url;
676: }
677:
678: /**
679: * Test the database drivers features given by the DatabaseMetaData object
680: */
681: public Vector[] TestDB(DatabaseMetaData d) throws SQLException
682: {
683:
684: Vector data[] = new Vector[2];
685: Vector[] rows = new Vector[120];
686: for (int i = 0; i < rows.length; ++i)
687: rows[i] = new Vector();
688: Vector columnNames = new Vector();
689: columnNames.add("Feature");
690: columnNames.add("Supported");
691:
692: Vector cols = new Vector();
693: rows[0].add("allProceduresAreCallable");
694: rows[0].add(new Boolean(d.allProceduresAreCallable()));
695: //boolean allProceduresAreCallable() throws SQLException;
696: rows[1].add("allTablesAreSelectable");
697: rows[1].add(new Boolean(d.allTablesAreSelectable()));
698: // boolean allTablesAreSelectable() throws SQLException;
699: rows[2].add("isReadOnly");
700: rows[2].add(new Boolean(d.isReadOnly()));
701: // boolean isReadOnly() throws SQLException;
702: rows[3].add("nullsAreSortedHigh");
703: rows[3].add(new Boolean(d.nullsAreSortedHigh()));
704: // boolean nullsAreSortedHigh() throws SQLException;
705: rows[4].add("nullsAreSortedLow");
706: rows[4].add(new Boolean(d.nullsAreSortedLow()));
707: // boolean nullsAreSortedLow() throws SQLException;
708: rows[5].add("nullsAreSortedAtStart");
709: rows[5].add(new Boolean(d.nullsAreSortedAtStart()));
710: // boolean nullsAreSortedAtStart() throws SQLException;
711: rows[6].add("nullsAreSortedAtEnd");
712: rows[6].add(new Boolean(d.nullsAreSortedAtEnd()));
713: // boolean nullsAreSortedAtEnd() throws SQLException;
714: rows[7].add("usesLocalFiles");
715: rows[7].add(new Boolean(d.usesLocalFiles()));
716: // boolean usesLocalFiles() throws SQLException;
717: rows[8].add("usesLocalFilePerTable");
718: rows[8].add(new Boolean(d.usesLocalFilePerTable()));
719: // boolean usesLocalFilePerTable() throws SQLException;
720: rows[9].add("supportsMixedCaseIdentifiers");
721: rows[9].add(new Boolean(d.supportsMixedCaseIdentifiers()));
722: //boolean supportsMixedCaseIdentifiers() throws SQLException;
723: rows[10].add("storesUpperCaseIdentifiers");
724: rows[10].add(new Boolean(d.storesUpperCaseIdentifiers()));
725: // boolean storesUpperCaseIdentifiers() throws SQLException;
726: rows[11].add("storesLowerCaseIdentifiers");
727: rows[11].add(new Boolean(d.storesLowerCaseIdentifiers()));
728: // boolean storesLowerCaseIdentifiers() throws SQLException;
729: rows[12].add("storesMixedCaseIdentifiers");
730: rows[12].add(new Boolean(d.storesMixedCaseIdentifiers()));
731: // boolean storesMixedCaseIdentifiers() throws SQLException;
732: rows[13].add("supportsMixedCaseQuotedIdentifiers");
733: rows[13].add(new Boolean(d.supportsMixedCaseQuotedIdentifiers()));
734: // boolean supportsMixedCaseQuotedIdentifiers() throws SQLException;
735: rows[14].add("storesUpperCaseQuotedIdentifiers");
736: rows[14].add(new Boolean(d.storesUpperCaseQuotedIdentifiers()));
737: // boolean storesUpperCaseQuotedIdentifiers() throws SQLException;
738: rows[15].add("storesLowerCaseQuotedIdentifiers");
739: rows[15].add(new Boolean(d.storesLowerCaseQuotedIdentifiers()));
740: //boolean storesLowerCaseQuotedIdentifiers() throws SQLException;
741: rows[16].add("storesMixedCaseQuotedIdentifiers");
742: rows[16].add(new Boolean(d.storesMixedCaseQuotedIdentifiers()));
743: // boolean storesMixedCaseQuotedIdentifiers() throws SQLException;
744: rows[17].add("supportsAlterTableWithAddColumn");
745: rows[17].add(new Boolean(d.supportsAlterTableWithAddColumn()));
746: // boolean supportsAlterTableWithAddColumn() throws SQLException;
747: rows[18].add("supportsAlterTableWithDropColumn");
748: rows[18].add(new Boolean(d.supportsAlterTableWithDropColumn()));
749: // boolean supportsAlterTableWithDropColumn() throws SQLException;
750: rows[19].add("nullPlusNonNullIsNull");
751: rows[19].add(new Boolean(d.nullPlusNonNullIsNull()));
752: // boolean nullPlusNonNullIsNull() throws SQLException;
753: rows[20].add("supportsConvert");
754: rows[20].add(new Boolean(d.supportsConvert()));
755: // boolean supportsConvert() throws SQLException;
756:
757: // boolean supportsConvert(int fromType, int toType) throws SQLException;
758: rows[21].add("supportsTableCorrelationNames");
759: rows[21].add(new Boolean(d.supportsTableCorrelationNames()));
760: // boolean supportsTableCorrelationNames() throws SQLException;
761: rows[22].add("supportsDifferentTableCorrelationNames");
762: rows[22].add(new Boolean(d.supportsDifferentTableCorrelationNames()));
763: // boolean supportsDifferentTableCorrelationNames() throws SQLException;
764: rows[23].add("supportsExpressionsInOrderBy");
765: rows[23].add(new Boolean(d.supportsExpressionsInOrderBy()));
766: // boolean supportsExpressionsInOrderBy() throws SQLException;
767: rows[24].add("supportsOrderByUnrelated");
768: rows[24].add(new Boolean(d.supportsOrderByUnrelated()));
769: // boolean supportsOrderByUnrelated() throws SQLException;
770: rows[25].add("supportsGroupBy");
771: rows[25].add(new Boolean(d.supportsGroupBy()));
772: // boolean supportsGroupBy() throws SQLException;
773: rows[26].add("supportsGroupByUnrelated");
774: rows[26].add(new Boolean(d.supportsGroupByUnrelated()));
775: // boolean supportsGroupByUnrelated() throws SQLException;
776: rows[27].add("supportsGroupByBeyondSelect");
777: rows[27].add(new Boolean(d.supportsGroupByBeyondSelect()));
778: // boolean supportsGroupByBeyondSelect() throws SQLException;
779: rows[28].add("supportsLikeEscapeClause");
780: rows[28].add(new Boolean(d.supportsLikeEscapeClause()));
781: // boolean supportsLikeEscapeClause() throws SQLException;
782: rows[29].add("supportsMultipleResultSets");
783: rows[29].add(new Boolean(d.supportsMultipleResultSets()));
784: // boolean supportsMultipleResultSets() throws SQLException;
785: rows[30].add("supportsMultipleTransactions");
786: rows[30].add(new Boolean(d.supportsMultipleTransactions()));
787: // boolean supportsMultipleTransactions() throws SQLException;
788: rows[31].add("supportsNonNullableColumns");
789: rows[31].add(new Boolean(d.supportsNonNullableColumns()));
790: // boolean supportsNonNullableColumns() throws SQLException;
791: rows[32].add("supportsMinimumSQLGrammar");
792: rows[32].add(new Boolean(d.supportsMinimumSQLGrammar()));
793: // boolean supportsMinimumSQLGrammar() throws SQLException;
794: rows[33].add("supportsCoreSQLGrammar");
795: rows[33].add(new Boolean(d.supportsCoreSQLGrammar()));
796: // boolean supportsCoreSQLGrammar() throws SQLException;
797: rows[34].add("supportsExtendedSQLGrammar");
798: rows[34].add(new Boolean(d.supportsExtendedSQLGrammar()));
799: // boolean supportsExtendedSQLGrammar() throws SQLException;
800: rows[35].add("supportsANSI92EntryLevelSQL");
801: rows[35].add(new Boolean(d.supportsANSI92EntryLevelSQL()));
802: // boolean supportsANSI92EntryLevelSQL() throws SQLException;
803: rows[36].add("supportsANSI92IntermediateSQL");
804: rows[36].add(new Boolean(d.supportsANSI92IntermediateSQL()));
805: //boolean supportsANSI92IntermediateSQL() throws SQLException;
806: rows[37].add("supportsANSI92FullSQL");
807: rows[37].add(new Boolean(d.supportsANSI92FullSQL()));
808: //boolean supportsANSI92FullSQL() throws SQLException;
809: rows[38].add("supportsIntegrityEnhancementFacility");
810: rows[38].add(new Boolean(d.supportsIntegrityEnhancementFacility()));
811: //boolean supportsIntegrityEnhancementFacility() throws SQLException;
812: rows[39].add("supportsOuterJoins");
813: rows[39].add(new Boolean(d.supportsOuterJoins()));
814: //boolean supportsOuterJoins() throws SQLException;
815: rows[40].add("supportsFullOuterJoins");
816: rows[40].add(new Boolean(d.supportsFullOuterJoins()));
817: //boolean supportsFullOuterJoins() throws SQLException;
818: rows[41].add("supportsLimitedOuterJoins");
819: rows[41].add(new Boolean(d.supportsLimitedOuterJoins()));
820: //boolean supportsLimitedOuterJoins() throws SQLException;
821: rows[42].add("isCatalogAtStart");
822: rows[42].add(new Boolean(d.isCatalogAtStart()));
823: //boolean isCatalogAtStart() throws SQLException;
824: rows[43].add("supportsSchemasInDataManipulation");
825: rows[43].add(new Boolean(d.supportsSchemasInDataManipulation()));
826: //boolean supportsSchemasInDataManipulation() throws SQLException;
827: rows[44].add("supportsSchemasInProcedureCalls");
828: rows[44].add(new Boolean(d.supportsSchemasInProcedureCalls()));
829: //boolean supportsSchemasInProcedureCalls() throws SQLException;
830: rows[45].add("supportsSchemasInTableDefinitions");
831: rows[45].add(new Boolean(d.supportsSchemasInTableDefinitions()));
832: //boolean supportsSchemasInTableDefinitions() throws SQLException;
833: rows[46].add("supportsSchemasInIndexDefinitions");
834: rows[46].add(new Boolean(d.supportsSchemasInIndexDefinitions()));
835: //boolean supportsSchemasInIndexDefinitions() throws SQLException;
836: rows[47].add("supportsSchemasInPrivilegeDefinitions");
837: rows[47].add(new Boolean(d.supportsSchemasInPrivilegeDefinitions()));
838: //boolean supportsSchemasInPrivilegeDefinitions() throws SQLException;
839: rows[48].add("supportsCatalogsInDataManipulation");
840: rows[48].add(new Boolean(d.supportsCatalogsInDataManipulation()));
841: //boolean supportsCatalogsInDataManipulation() throws SQLException;
842: rows[49].add("supportsCatalogsInProcedureCalls");
843: rows[49].add(new Boolean(d.supportsCatalogsInProcedureCalls()));
844: //boolean supportsCatalogsInProcedureCalls() throws SQLException;
845: rows[50].add("supportsCatalogsInTableDefinitions");
846: rows[50].add(new Boolean(d.supportsCatalogsInTableDefinitions()));
847: //boolean supportsCatalogsInTableDefinitions() throws SQLException;
848: rows[51].add("supportsCatalogsInIndexDefinitions");
849: rows[51].add(new Boolean(d.supportsCatalogsInIndexDefinitions()));
850: //boolean supportsCatalogsInIndexDefinitions() throws SQLException;
851: rows[52].add("supportsCatalogsInPrivilegeDefinitions");
852: rows[52].add(new Boolean(d.supportsCatalogsInPrivilegeDefinitions()));
853: //boolean supportsCatalogsInPrivilegeDefinitions() throws SQLException;
854: rows[53].add("supportsPositionedDelete");
855: rows[53].add(new Boolean(d.supportsPositionedDelete()));
856: //boolean supportsPositionedDelete() throws SQLException;
857: rows[54].add("supportsPositionedUpdate");
858: rows[54].add(new Boolean(d.supportsPositionedUpdate()));
859: //boolean supportsPositionedUpdate() throws SQLException;
860: rows[55].add("supportsSelectForUpdate");
861: rows[55].add(new Boolean(d.supportsSelectForUpdate()));
862: //boolean supportsSelectForUpdate() throws SQLException;
863: rows[56].add("supportsStoredProcedures");
864: rows[56].add(new Boolean(d.supportsStoredProcedures()));
865: //boolean supportsStoredProcedures() throws SQLException;
866: rows[57].add("supportsSubqueriesInComparisons");
867: rows[57].add(new Boolean(d.supportsSubqueriesInComparisons()));
868: //boolean supportsSubqueriesInComparisons() throws SQLException;
869: rows[58].add("supportsSubqueriesInExists");
870: rows[58].add(new Boolean(d.supportsSubqueriesInExists()));
871: //boolean supportsSubqueriesInExists() throws SQLException;
872: rows[59].add("supportsSubqueriesInIns");
873: rows[59].add(new Boolean(d.supportsSubqueriesInIns()));
874: //boolean supportsSubqueriesInIns() throws SQLException;
875: rows[60].add("supportsSubqueriesInQuantifieds");
876: rows[60].add(new Boolean(d.supportsSubqueriesInQuantifieds()));
877: //boolean supportsSubqueriesInQuantifieds() throws SQLException;
878: rows[61].add("supportsCorrelatedSubqueries");
879: rows[61].add(new Boolean(d.supportsCorrelatedSubqueries()));
880: //boolean supportsCorrelatedSubqueries() throws SQLException;
881: rows[62].add("supportsUnion");
882: rows[62].add(new Boolean(d.supportsUnion()));
883: //boolean supportsUnion() throws SQLException;
884: rows[63].add("supportsUnionAll");
885: rows[63].add(new Boolean(d.supportsUnionAll()));
886: //boolean supportsUnionAll() throws SQLException;
887: rows[64].add("supportsOpenCursorsAcrossCommit");
888: rows[64].add(new Boolean(d.supportsOpenCursorsAcrossCommit()));
889: //boolean supportsOpenCursorsAcrossCommit() throws SQLException;
890: rows[65].add("supportsOpenCursorsAcrossRollback");
891: rows[65].add(new Boolean(d.supportsOpenCursorsAcrossRollback()));
892: //boolean supportsOpenCursorsAcrossRollback() throws SQLException;
893: rows[66].add("supportsOpenStatementsAcrossCommit");
894: rows[66].add(new Boolean(d.supportsOpenStatementsAcrossCommit()));
895: //boolean supportsOpenStatementsAcrossCommit() throws SQLException;
896: rows[67].add("supportsOpenStatementsAcrossRollback");
897: rows[67].add(new Boolean(d.supportsOpenStatementsAcrossRollback()));
898: //boolean supportsOpenStatementsAcrossRollback() throws SQLException;
899: rows[68].add("doesMaxRowSizeIncludeBlobs");
900: rows[68].add(new Boolean(d.doesMaxRowSizeIncludeBlobs()));
901: //boolean doesMaxRowSizeIncludeBlobs() throws SQLException;
902: rows[69].add("supportsTransactions");
903: rows[69].add(new Boolean(d.supportsTransactions()));
904: //boolean supportsTransactions() throws SQLException;
905: rows[70].add("supportsTransactionIsolationLevel");
906: rows[70].add(new Boolean(d.supportsTransactionIsolationLevel(1)));
907: //boolean supportsTransactionIsolationLevel(int level) throws SQLException;
908: rows[71].add("supportsDataDefinitionAndDataManipulationTransactions");
909: rows[71].add(new Boolean(d.supportsDataDefinitionAndDataManipulationTransactions()));
910: //boolean supportsDataDefinitionAndDataManipulationTransactions() throws SQLException;
911: rows[72].add("supportsDataManipulationTransactionsOnly");
912: rows[72].add(new Boolean(d.supportsDataManipulationTransactionsOnly()));
913: //boolean supportsDataManipulationTransactionsOnly() throws SQLException;
914: rows[73].add("dataDefinitionCausesTransactionCommit");
915: rows[73].add(new Boolean(d.dataDefinitionCausesTransactionCommit()));
916: //boolean dataDefinitionCausesTransactionCommit() throws SQLException;
917: rows[74].add("dataDefinitionIgnoredInTransactions");
918: rows[74].add(new Boolean(d.dataDefinitionIgnoredInTransactions()));
919: //boolean dataDefinitionIgnoredInTransactions() throws SQLException;
920: rows[75].add("getMaxBinaryLiteralLength");
921: rows[75].add(new Integer(d.getMaxBinaryLiteralLength()));
922: // int getMaxBinaryLiteralLength() throws SQLException;
923: rows[76].add("getMaxCharLiteralLength");
924: rows[76].add(new Integer(d.getMaxCharLiteralLength()));
925: //int getMaxCharLiteralLength() throws SQLException;
926: rows[77].add("getMaxColumnNameLength");
927: rows[77].add(new Integer(d.getMaxColumnNameLength()));
928: // int getMaxColumnNameLength() throws SQLException;
929: rows[78].add("getMaxColumnsInGroupBy");
930: rows[78].add(new Integer(d.getMaxColumnsInGroupBy()));
931: //int getMaxColumnsInGroupBy() throws SQLException;
932: rows[79].add("getMaxColumnsInIndex");
933: rows[79].add(new Integer(d.getMaxColumnsInIndex()));
934: //int getMaxColumnsInIndex() throws SQLException;
935: rows[80].add("getMaxColumnsInOrderBy");
936: rows[80].add(new Integer(d.getMaxColumnsInOrderBy()));
937: //int getMaxColumnsInOrderBy() throws SQLException;
938: rows[81].add("getMaxColumnsInSelect");
939: rows[81].add(new Integer(d.getMaxColumnsInSelect()));
940: //int getMaxColumnsInSelect() throws SQLException;
941: rows[82].add("getMaxColumnsInTable");
942: rows[82].add(new Integer(d.getMaxColumnsInTable()));
943: //int getMaxColumnsInTable() throws SQLException;
944: rows[83].add("getMaxConnections");
945: rows[83].add(new Integer(d.getMaxConnections()));
946: //int getMaxConnections() throws SQLException;
947: rows[84].add("getMaxCursorNameLength");
948: rows[84].add(new Integer(d.getMaxCursorNameLength()));
949: // int getMaxCursorNameLength() throws SQLException;
950: rows[85].add("getMaxIndexLength");
951: rows[85].add(new Integer(d.getMaxIndexLength()));
952: //int getMaxIndexLength() throws SQLException;
953: rows[86].add("getMaxSchemaNameLength");
954: rows[86].add(new Integer(d.getMaxSchemaNameLength()));
955: //int getMaxSchemaNameLength() throws SQLException;
956: rows[87].add("getMaxProcedureNameLength");
957: rows[87].add(new Integer(d.getMaxProcedureNameLength()));
958: //int getMaxProcedureNameLength() throws SQLException;
959: rows[88].add("getMaxCatalogNameLength");
960: rows[88].add(new Integer(d.getMaxCatalogNameLength()));
961: //int getMaxCatalogNameLength() throws SQLException;
962: rows[89].add("getMaxRowSize");
963: rows[89].add(new Integer(d.getMaxRowSize()));
964: //int getMaxRowSize() throws SQLException;
965: rows[90].add("getMaxStatementLength");
966: rows[90].add(new Integer(d.getMaxStatementLength()));
967: //int getMaxStatementLength() throws SQLException;
968: rows[91].add("getMaxStatements");
969: rows[91].add(new Integer(d.getMaxStatements()));
970: //int getMaxStatements() throws SQLException;
971: rows[92].add("getMaxTableNameLength");
972: rows[92].add(new Integer(d.getMaxTableNameLength()));
973: //int getMaxTableNameLength() throws SQLException;
974: rows[93].add("getMaxTablesInSelect");
975: rows[93].add(new Integer(d.getMaxTablesInSelect()));
976: //int getMaxTablesInSelect() throws SQLException;
977: rows[94].add("getMaxUserNameLength");
978: rows[94].add(new Integer(d.getMaxUserNameLength()));
979: // int getMaxUserNameLength() throws SQLException;
980: rows[95].add("getDefaultTransactionIsolation");
981: rows[95].add(new Integer(d.getDefaultTransactionIsolation()));
982: //int getDefaultTransactionIsolation() throws SQLException;
983:
984: rows[96].add("getDatabaseProductName");
985: rows[96].add(d.getDatabaseProductName());
986: // String getDatabaseProductName() throws SQLException;
987: rows[97].add("getDatabaseProductVersion");
988: rows[97].add(d.getDatabaseProductVersion());
989: //String getDatabaseProductVersion() throws SQLException;
990:
991: rows[98].add("getURL");
992: rows[98].add(d.getURL());
993: //String getURL() throws SQLException;
994: rows[99].add("getUserName");
995: rows[99].add(d.getUserName());
996: //String getUserName() throws SQLException;
997: rows[100].add("getDriverName");
998: rows[100].add(d.getDriverName());
999: // String getDriverName() throws SQLException;
1000: rows[101].add("getIdentifierQuoteString");
1001: rows[101].add(d.getIdentifierQuoteString());
1002: //String getIdentifierQuoteString() throws SQLException;
1003:
1004: rows[102].add("getDriverVersion");
1005: rows[102].add(d.getDriverVersion());
1006: //String getDriverVersion() throws SQLException;
1007: rows[103].add("getDriverMajorVersion");
1008: rows[103].add(new Integer(d.getDriverMajorVersion()));
1009: //int getDriverMajorVersion();
1010: rows[104].add("getDriverMinorVersion");
1011: rows[104].add(new Integer(d.getDriverMinorVersion()));
1012: //int getDriverMinorVersion();
1013: rows[105].add("getSQLKeywords");
1014: rows[105].add(d.getSQLKeywords());
1015: //String getSQLKeywords() throws SQLException;
1016: rows[106].add("getNumericFunctions");
1017: rows[106].add(d.getNumericFunctions());
1018: //String getNumericFunctions() throws SQLException;
1019: rows[107].add("getStringFunctions");
1020: rows[107].add(d.getStringFunctions());
1021: // String getStringFunctions() throws SQLException;
1022: rows[108].add("getSystemFunctions");
1023: rows[108].add(d.getSystemFunctions());
1024: //String getSystemFunctions() throws SQLException;
1025: rows[109].add("getTimeDateFunctions");
1026: rows[109].add(d.getTimeDateFunctions());
1027: //String getTimeDateFunctions() throws SQLException;
1028: rows[110].add("getSearchStringEscape");
1029: rows[110].add(d.getSearchStringEscape());
1030: //String getSearchStringEscape() throws SQLException;
1031: rows[111].add("getExtraNameCharacters");
1032: rows[111].add(d.getExtraNameCharacters());
1033: //String getExtraNameCharacters() throws SQLException;
1034: rows[112].add("getSchemaTerm");
1035: rows[112].add(d.getSchemaTerm());
1036: //String getSchemaTerm() throws SQLException;
1037: rows[113].add("getProcedureTerm");
1038: rows[113].add(d.getProcedureTerm());
1039: //String getProcedureTerm() throws SQLException;
1040: rows[114].add("getCatalogTerm");
1041: rows[114].add(d.getCatalogTerm());
1042: // String getCatalogTerm() throws SQLException;
1043: rows[115].add("getCatalogSeparator");
1044: rows[115].add(d.getCatalogSeparator());
1045: //String getCatalogSeparator() throws SQLException;
1046:
1047: /*
1048: boolean supportsResultSetType(int type) throws SQLException;
1049:
1050: boolean supportsResultSetConcurrency(int type, int concurrency) throws SQLException;
1051:
1052: boolean ownUpdatesAreVisible(int type) throws SQLException;
1053:
1054: boolean ownDeletesAreVisible(int type) throws SQLException;
1055:
1056: boolean ownInsertsAreVisible(int type) throws SQLException;
1057:
1058: boolean othersUpdatesAreVisible(int type) throws SQLException;
1059:
1060: boolean othersDeletesAreVisible(int type) throws SQLException;
1061:
1062: boolean othersInsertsAreVisible(int type) throws SQLException;
1063: boolean updatesAreDetected(int type) throws SQLException;
1064: boolean deletesAreDetected(int type) throws SQLException;
1065:
1066: boolean insertsAreDetected(int type) throws SQLException;
1067: */
1068: // not in filemaker
1069: // rows[96].add("supportsBatchUpdates");
1070: // rows[96].add(new Boolean(d.supportsBatchUpdates()));
1071: //boolean supportsBatchUpdates() throws SQLException;
1072:
1073: /*
1074: ResultSet getProcedures(String catalog, String schemaPattern, String procedureNamePattern) throws SQLException;
1075:
1076: ResultSet getProcedureColumns(String catalog, String schemaPattern, String procedureNamePattern, String columnNamePattern) throws SQLException;
1077: ResultSet getTables(String catalog, String schemaPattern, String tableNamePattern, String types[]) throws SQLException;
1078: ResultSet getSchemas() throws SQLException;
1079: ResultSet getCatalogs() throws SQLException;
1080: ResultSet getTableTypes() throws SQLException;
1081: ResultSet getColumns(String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern) throws SQLException;
1082: ResultSet getPrimaryKeys(String catalog, String schema, String table) throws SQLException;
1083: ResultSet getImportedKeys(String catalog, String schema, String table) throws SQLException;
1084: ResultSet getExportedKeys(String catalog, String schema, String table) throws SQLException;
1085: ResultSet getCrossReference(String primaryCatalog, String primarySchema, String primaryTable, String foreignCatalog, String foreignSchema, String foreignTable) throws SQLException;
1086: ResultSet getTypeInfo() throws SQLException;
1087: ResultSet getIndexInfo(String catalog, String schema, String table, boolean unique, boolean approximate) throws SQLException;
1088:
1089: ResultSet getUDTs(String catalog, String schemaPattern, String typeNamePattern, int[] types) throws SQLException;
1090:
1091: Connection getConnection() throws SQLException;
1092:
1093: */
1094: for (int i = 0; i < rows.length; ++i)
1095: cols.add(rows[i]);
1096: data[0] = cols;
1097: data[1] = columnNames;
1098: return data;
1099: }
1100: public Vector getNextRow() throws Exception
1101: {
1102:
1103: if (result == null)
1104: return null;
1105: boolean check = false;
1106: ResultSet resultSet = result;
1107: ResultSetMetaData metaData = resultSet.getMetaData();
1108: int columnCount = metaData.getColumnCount();
1109: Vector tableData = new Vector();
1110: check = resultSet.next();
1111: // System.out.println("hallo check "+check);
1112: if (!check)
1113: return null;
1114: Vector tableRow = new Vector(), m_columnClasses = new Vector();
1115: for (int i = 1; i <= columnCount; i++)
1116: {
1117: // repeating fields and fields from related databases may contain
1118: // multliple data values; the data values are stored using
1119: // a Vector which is then added to the tableRow
1120: // if (metaData instanceof ResultSetMetaDataExt)
1121: if ((metaData instanceof ResultSetMetaDataExt) && (((ResultSetMetaDataExt) metaData).isRelated(i) || ((ResultSetMetaDataExt) metaData).isRepeating(i)))
1122: {
1123: //System.out.println("Related fields");
1124: // retrieve the repeating or related field contents as a
1125: // com.fmi.jdbc.Array via the ResultSet.getObject method
1126: com.fmi.jdbc.Array array = (com.fmi.jdbc.Array) resultSet.getObject(i);
1127: // create a Vector for storing all of the data values
1128: ArrayList columnData = new ArrayList();
1129: try
1130: {
1131:
1132: // call the Array.getStringArray method since the data will
1133: // only be displayed
1134: Object[] fieldData = (Object[]) array.getArray();
1135:
1136: if (fieldData != null)
1137: {
1138: // add each value to the Vector
1139: for (int j = 0; j < fieldData.length; j++)
1140: {
1141: if (fieldData[j] != null)
1142: columnData.add(fieldData[j]);
1143: }
1144: }
1145: } catch (Exception e)
1146: {
1147: //System.out.println(e);
1148: }
1149:
1150: if (columnData.isEmpty())
1151: tableRow.add(null);
1152: else
1153: tableRow.addElement(columnData);
1154: //System.out.println(columnData);
1155: //System.out.println("Related fields"+columnData.size()+" "+tableRow.size());
1156:
1157: // m_columnClasses.addElement(java.util.Vector.class);
1158: } else if (metaData.getColumnType(i) == Types.LONGVARBINARY)
1159: {
1160: // use the ResultSet.getObject method for retrieving images
1161: // from FileMaker Pro container fields; the ResultSet.getObject
1162: // method returns a java.awt.Image object for FileMaker Pro
1163: // container fields
1164:
1165: try
1166: {
1167: tableRow.addElement(resultSet.getObject(i));
1168: } catch (Exception e)
1169: {
1170: // TODO Auto-generated catch block
1171: // e.printStackTrace();
1172: tableRow.addElement(null);
1173: }
1174: // m_columnClasses.addElement(java.awt.Image.class);
1175: } else if (metaData.getColumnType(i) == Types.TIME)
1176: {
1177: // use the ResultSet.getObject method for retieving images
1178: // from FileMaker Pro container fields; the ResultSet.getObject
1179: // method returns a java.awt.Image object for FileMaker Pro
1180: // container fields
1181: try
1182: {
1183: tableRow.addElement(resultSet.getTime(i).toString());
1184: // m_columnClasses.addElement(java.sql.Time.class);
1185: } catch (Exception e)
1186: {
1187:
1188: String value = resultSet.getString(i);
1189: if (value != null)
1190: {
1191: //System.out.println("SQLTime new "+Time.valueOf("17:00:00").toString());
1192: int index = 0;
1193: for (int j = 0; j < value.length(); ++j)
1194: {
1195: if (!Character.isLetter(value.charAt(j)))
1196: index = j + 1;
1197: else
1198: break;
1199: }
1200:
1201: tableRow.addElement(value.substring(0, index));
1202: //m_columnClasses.addElement(java.sql.Time.class);
1203: } else
1204: tableRow.add(null);
1205: // m_columnClasses.addElement(String.class);
1206: } // to catch
1207:
1208: } else if (metaData.getColumnType(i) == Types.DATE)
1209: {
1210: // use the ResultSet.getObject method for retieving images
1211: // from FileMaker Pro container fields; the ResultSet.getObject
1212: // method returns a java.awt.Image object for FileMaker Pro
1213: // container fields
1214:
1215: tableRow.addElement(resultSet.getDate(i));
1216: // m_columnClasses.addElement(java.sql.Date.class);
1217: } else if (metaData.getColumnTypeName(i) == "NUMBER")
1218: {
1219: // use the ResultSet.getObject method for retieving images
1220: // from FileMaker Pro container fields; the ResultSet.getObject
1221: // method returns a java.awt.Image object for FileMaker Pro
1222: // container fields
1223: try
1224: {
1225: tableRow.addElement(new Integer(resultSet.getInt(i)));
1226: // m_columnClasses.addElement(Integer.class);
1227:
1228: } catch (Exception e)
1229: {
1230:
1231: StringBuffer number = new StringBuffer();
1232: String value = resultSet.getString(i);
1233: System.out.println(value);
1234: for (int c = 0; c < value.length(); ++c)
1235: {
1236: if (Character.isDigit(value.charAt(c)))
1237: {
1238: number.append(value.charAt(c));
1239: }
1240: }
1241: if (number.length() > 0)
1242: {
1243: tableRow.addElement(null);
1244: // m_columnClasses.addElement(Integer.class);
1245: } else
1246: tableRow.addElement(null);
1247: }
1248: } else
1249: {
1250: // all other field values are retrieved as strings and
1251: // added to the tableRow Vector
1252: // System.out.println("row "+resultSet.getString(i));
1253: try
1254: {
1255: byte[] b = null;
1256: if (metaData instanceof ResultSetMetaDataExt)
1257: b = resultSet.getBytes(i);
1258: String utf8 = null;
1259: utf8 = (b == null) ? null : new String(b);
1260: if (metaData instanceof ResultSetMetaDataExt)
1261: tableRow.addElement((b != null) ? new String(utf8.getBytes()) : null);
1262: else
1263: {
1264: // byte[] val = resultSet.getBytes(i);
1265: tableRow.add(resultSet.getString(i));
1266: //tableRow.addElement((val==null) ? null:new String(val,"UTF-8"));
1267: }
1268: } catch (Exception e)
1269: {
1270: System.out.println("Hey I Got an error" + e);
1271: e.printStackTrace();
1272: }
1273: // m_columnClasses.addElement(java.lang.String.class);
1274: }
1275: }
1276: // tableData.addElement(tableRow);
1277: if (check)
1278: return tableRow;
1279: else
1280: return null;
1281: }
1282: class ConnectionPool
1283: {
1284: String user = "", passwd = "", url = "";
1285: Connection con;
1286: public ConnectionPool(String url, String user, String passwd, Connection con)
1287: {
1288: this.con = con;
1289: this.user = user;
1290: this.passwd = passwd;
1291: this.url = url;
1292: }
1293:
1294: }
1295: public String getQC()
1296: {
1297: // if (connection == null)
1298: // return "";
1299:
1300: // check if connection null if null try to get one
1301: if (connection == null)
1302: try
1303: {
1304: getConnection();
1305: } catch (Exception e)
1306: {
1307: if (FM2SQL.debug)
1308: System.out.println("cannot get a connection");
1309: }
1310: if (connection == null)
1311: {
1312: if (url.toLowerCase().indexOf("fmpro") >= 0 || url.toLowerCase().indexOf("postgres") >= 0)
1313: quoteChar = "\"";
1314: else if (url.toLowerCase().indexOf("mysql") >= 0)
1315: quoteChar = "`";
1316: }
1317: if (quoteChar == null)
1318: quoteChar = "\""; // needed for postgres
1319: return quoteChar;
1320: }
1321: public int getRowCount(String query) throws SQLException
1322: {
1323: String table = query.substring(query.indexOf("from") + 4).trim();
1324: int index = table.indexOf(" ");
1325: table = table.substring(0, (index >= 0) ? index : table.length());
1326: System.out.println(table);
1327: Statement stm = null;
1328:
1329: if (metaData instanceof ResultSetMetaDataExt)
1330: return 1000;
1331: if (!connection.isClosed())
1332: stm = connection.createStatement();
1333: stm.setMaxRows(1);
1334: ResultSet resultSet = stm.executeQuery("select count(*) from " + table);
1335: resultSet.next();
1336: return resultSet.getInt(1);
1337: }
1338:
1339: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>