1 33 34 package com.internetcds.jdbc.tds; 35 36 37 38 import java.sql.*; 39 40 41 66 public class DatabaseMetaData implements java.sql.DatabaseMetaData 67 { 68 public static final String cvsVersion = "$Id: DatabaseMetaData.java,v 1.1 2006/06/23 10:39:04 sinisa Exp $"; 69 70 final boolean verbose = true; 71 72 73 76 final int procedureResultUnknown = 0; 77 80 final int procedureNoResult = 1; 81 84 final int procedureReturnsResult = 2; 85 86 89 final int procedureColumnUnknown = 0; 90 91 94 final int procedureColumnIn = 1; 95 96 99 final int procedureColumnInOut = 2; 100 101 104 final int procedureColumnOut = 4; 105 108 final int procedureColumnReturn = 5; 109 110 113 final int procedureColumnResult = 3; 114 115 118 final int procedureNoNulls = 0; 119 120 123 final int procedureNullable = 1; 124 125 128 final int procedureNullableUnknown = 2; 129 130 131 134 final int columnNoNulls = 0; 135 136 139 final int columnNullable = 1; 140 141 144 final int columnNullableUnknown = 2; 145 146 149 final int bestRowTemporary = 0; 150 151 154 final int bestRowTransaction = 1; 155 156 159 final int bestRowSession = 2; 160 161 164 final int bestRowUnknown = 0; 165 166 169 final int bestRowNotPseudo = 1; 170 171 174 final int bestRowPseudo = 2; 175 176 179 final int versionColumnUnknown = 0; 180 181 184 final int versionColumnNotPseudo = 1; 185 186 189 final int versionColumnPseudo = 2; 190 191 196 final int importedKeyCascade = 0; 197 198 202 final int importedKeyRestrict = 1; 203 204 208 final int importedKeySetNull = 2; 209 210 214 final int importedKeyNoAction = 3; 215 216 220 final int importedKeySetDefault = 4; 221 222 225 final int importedKeyInitiallyDeferred = 5; 226 227 230 final int importedKeyInitiallyImmediate = 6; 231 232 235 final int importedKeyNotDeferrable = 7; 236 237 240 final int typeNoNulls = 0; 241 242 245 final int typeNullable = 1; 246 247 250 final int typeNullableUnknown = 2; 251 252 255 final int typePredNone = 0; 256 257 260 final int typePredChar = 1; 261 262 265 final int typePredBasic = 2; 266 267 270 final int typeSearchable = 3; 271 272 276 final short tableIndexStatistic = 0; 277 278 281 final short tableIndexClustered = 1; 282 283 286 final short tableIndexHashed = 2; 287 288 291 final short tableIndexOther = 3; 292 293 294 Tds tds; 298 299 300 301 302 java.sql.Connection connection; 303 304 305 private void debugPrintln(String s) 306 { 307 if (verbose) 308 { 309 System.out.println(s); 310 } 311 } 312 313 private void debugPrint(String s) 314 { 315 if (verbose) 316 { 317 System.out.print(s); 318 } 319 } 320 321 322 private void NotImplemented() throws SQLException 323 { 324 try 325 { 326 throw new SQLException("Not implemented"); 327 } 328 catch (SQLException e) 329 { 330 e.printStackTrace(); 331 } 332 throw new SQLException("Not implemented"); 333 } 334 335 336 public DatabaseMetaData( 337 Object connection_, 338 Tds tds_) 339 { 340 connection = (java.sql.Connection )connection_; 341 tds = tds_; 342 } 343 344 345 348 355 public boolean allProceduresAreCallable() throws SQLException 356 { 357 359 return true; } 361 362 363 370 public boolean allTablesAreSelectable() throws SQLException 371 { 372 374 return false; 377 } 378 379 380 387 public boolean dataDefinitionCausesTransactionCommit() 388 throws SQLException 389 { 390 NotImplemented(); return false; 391 } 392 393 394 400 public boolean dataDefinitionIgnoredInTransactions() 401 throws SQLException 402 { 403 NotImplemented(); return false; 404 } 405 406 407 408 415 public boolean doesMaxRowSizeIncludeBlobs() throws SQLException 416 { 417 return false; 418 } 419 420 421 422 458 public java.sql.ResultSet getBestRowIdentifier( 459 String catalog, 460 String schema, 461 String table, 462 int scope, 463 boolean nullable) 464 throws SQLException 465 { 466 debugPrintln("Inside getBestRowIdentifier with catalog=|" + catalog 467 + "|, schema=|" + schema + "|, table=|" + table +"|, " 468 + " scope=" + scope + ", nullable=" + nullable); 469 470 NotImplemented(); return null; 471 } 472 473 474 487 public java.sql.ResultSet getCatalogs() 488 throws SQLException 489 { 490 String tmpName = "#t#" + UniqueId.getUniqueId(); 492 final String sql = 493 " create table " + tmpName + " " + 494 " ( " + 495 " q char(30) not null, " + 496 " o char(30) null, " + 497 " n char(30) null, " + 498 " t char(30) null, " + 499 " r varchar(255) null " + 500 " ) " + 501 " " + 502 " insert into " + tmpName + " EXEC sp_tables ' ', ' ', '%', null " + 503 " " + 504 " select q from " + tmpName + " " + 505 ""; 506 java.sql.Statement stmt = connection.createStatement(); 507 java.sql.ResultSet rs; 508 509 510 if (stmt.execute(sql)) 511 { 512 throw new SQLException("Internal error. Confused"); 513 } 514 515 516 if (null != (rs = stmt.getResultSet())) 518 { 519 throw new SQLException("Internal error. Confused"); 520 } 521 522 if (null != (rs = stmt.getResultSet())) 524 { 525 527 531 return rs; 532 } 533 534 if (null == (rs = stmt.getResultSet())) 536 { 537 throw new SQLException("Internal error. Confused"); 538 } 539 return rs; 540 } 541 542 543 544 550 public String getCatalogSeparator() throws SQLException 551 { 552 return "."; 553 } 554 555 556 557 563 public String getCatalogTerm() throws SQLException 564 { 565 566 return "database"; 567 } 568 569 570 571 600 public java.sql.ResultSet getColumnPrivileges(String catalog, String schema, 601 String table, String columnNamePattern) 602 throws SQLException 603 { 604 NotImplemented(); return null; 605 } 606 607 608 658 public java.sql.ResultSet getColumns(String catalog, String schemaPattern, 659 String tableNamePattern, String columnNamePattern) 660 throws SQLException 661 { 662 debugPrintln("Inside of getColumn"); 663 debugPrintln(" catalog is |" + catalog + "|"); 664 debugPrintln(" schemaPattern is " + schemaPattern); 665 debugPrintln(" tableNamePattern is " + tableNamePattern); 666 debugPrintln(" columnNamePattern is " + columnNamePattern); 667 668 return getColumns_SQLServer65(catalog, schemaPattern, 669 tableNamePattern, columnNamePattern); 670 } 671 672 673 private java.sql.ResultSet getColumns_SQLServer65( 674 String catalog, 675 String schemaPattern, 676 String tableNamePattern, 677 String columnNamePattern) 678 throws SQLException 679 { 680 int i; 681 682 String sql = null; 683 java.sql.Statement tmpTableStmt = connection.createStatement(); 684 String catalogCriteria; 685 686 String tmpTableName = "##t#" + UniqueId.getUniqueId(); 690 String lookup = "#l#" + UniqueId.getUniqueId(); 691 692 sql = 694 "create table " + tmpTableName + " ( " + 695 " TABLE_CAT char(32) null, " + 696 " TABLE_SCHEM char(32) null, " + 697 " TABLE_NAME char(32) null, " + 698 " COLUMN_NAME char(32) null, " + 699 " DATA_TYPE integer null, " + 700 " TYPE_NAME char(32) null, " + 701 " COLUMN_SIZE integer null, " + 702 " BUFFER_LENGTH integer null, " + 703 " DECIMAL_DIGITS integer null, " + 704 " NUM_PREC_RADIX integer null, " + 705 " NULLABLE integer null, " + 706 " REMARKS char(255) null, " + 707 " COLUMN_DEF char(255) null, " + 708 " SQL_DATA_TYPE integer null, " + 709 " SQL_DATETIME_SUB integer null, " + 710 " CHAR_OCTET_LENGTH integer null, " + 711 " ORDINAL_POSITION integer null, " + 712 " IS_NULLABLE char(3)) " + 713 ""; 714 tmpTableStmt.execute(sql); 715 716 sql = 718 "create table " + lookup + " ( " + 719 " native_type integer primary key, " + 720 " jdbc_type integer not null) "; 721 tmpTableStmt.execute(sql); 722 723 sql = 724 "insert into " + lookup + " values ( 31, 1111) " + "insert into " + lookup + " values ( 34, 1111) " + "insert into " + lookup + " values ( 35, -1) " + "insert into " + lookup + " values ( 37, -3) " + "insert into " + lookup + " values ( 38, 4) " + "insert into " + lookup + " values ( 39, 12) " + "insert into " + lookup + " values ( 45, -2) " + "insert into " + lookup + " values ( 47, 1) " + "insert into " + lookup + " values ( 48, -6) " + "insert into " + lookup + " values ( 50, -7) " + "insert into " + lookup + " values ( 52, 5) " + "insert into " + lookup + " values ( 56, 4) " + "insert into " + lookup + " values ( 58, 93) " + "insert into " + lookup + " values ( 59, 7) " + "insert into " + lookup + " values ( 60, 1111) " + "insert into " + lookup + " values ( 61, 93) " + "insert into " + lookup + " values ( 62, 8) " + "insert into " + lookup + " values (106, 3) " + "insert into " + lookup + " values (108, 2) " + "insert into " + lookup + " values (109, 8) " + "insert into " + lookup + " values (110, 1111) " + "insert into " + lookup + " values (111, 93) " + "insert into " + lookup + " values (112, 1111) " + ""; 748 tmpTableStmt.execute(sql); 749 750 751 java.sql.ResultSet rs = getTables(null, "%", "%", null); 755 while(rs.next()) 756 { 757 String cat = rs.getString(1); 758 759 sql = 763 "insert into " + tmpTableName + " " + 764 "select " + 765 " TABLE_CAT='" + cat + "', " + 766 " TABLE_SCHEM=USER_NAME(o.uid), " + 767 " TABLE_NAME=o.name, " + 768 " COLUMN_NAME=c.name, " + 769 " DATA_TYPE=l.jdbc_type, " + 770 " TYPE_NAME=t.name, " + 771 " COLUMN_SIZE=c.prec, " + 772 " BUFFER_LENGTH=0, " + 773 " DECIMAL_DIGITS=c.scale, " + 774 " NUM_PREC_RADIX=10, " + 775 " NULLABLE=convert(integer, " + 776 " convert(bit, c.status&8)), " + 777 " REMARKS=null, " + 778 " COLUMN_DEF=null, " + 779 " SQL_DATATYPE=c.type, " + 780 " SQL_DATETIME_SUB=0, " + 781 " CHAR_OCTET_LENGTH=c.length, " + 782 " ORDINAL_POSITION=c.colid, " + 783 " IS_NULLABLE= " + 784 " convert(char(3), rtrim(substring " + 785 " ('NO YES', " + 786 " (c.status&8)+1,3))) " + 787 "from " + 788 " " + cat + ".dbo.sysobjects o, " + 789 " " + cat + ".dbo.syscolumns c, " + 790 " " + lookup + " l, " + 791 " systypes t " + 792 "where o.type in ('V', 'U') and o.id=c.id " + 793 " and t.type=c.type " + 794 " and l.native_type=c.type " + 795 ""; 796 try 798 { 799 tmpTableStmt.executeUpdate(sql); 800 } 801 catch (SQLException e) 802 { 803 804 } 805 } 806 rs.close(); 807 808 809 if (catalog == null) 810 { 811 catalog = ""; 812 catalogCriteria = " (TABLE_CAT like '%' or TABLE_CAT=?) "; 813 } 814 else 815 { 816 catalogCriteria = " TABLE_CAT=? "; 817 } 818 819 sql = 820 "select distinct * from " + tmpTableName + " where " + 821 catalogCriteria + " and " + 822 " TABLE_SCHEM like ? and TABLE_NAME like ? and " + 823 " COLUMN_NAME like ? " + 824 "order by TABLE_SCHEM, TABLE_NAME, ORDINAL_POSITION " ; 825 826 System.out.println("The query is \n" + sql); 827 828 java.sql.PreparedStatement ps = connection.prepareStatement(sql); 829 830 ps.setString(1, catalog); 831 ps.setString(2, schemaPattern); 832 ps.setString(3, tableNamePattern); 833 ps.setString(4, columnNamePattern); 834 rs = ps.executeQuery(); 835 836 tmpTableStmt.close(); 838 839 return rs; 840 } 841 842 843 919 public java.sql.ResultSet getCrossReference( 920 String primaryCatalog, String primarySchema, String primaryTable, 921 String foreignCatalog, String foreignSchema, String foreignTable 922 ) throws SQLException 923 { 924 NotImplemented(); return null; 925 } 926 927 928 934 public String getDatabaseProductName() throws SQLException 935 { 936 return tds.getDatabaseProductName(); 937 } 938 939 940 946 public String getDatabaseProductVersion() throws SQLException 947 { 948 return tds.getDatabaseProductVersion(); 949 } 950 951 952 954 962 public int getDefaultTransactionIsolation() throws SQLException 963 { 964 return Connection.TRANSACTION_READ_COMMITTED; 966 } 967 968 969 974 public int getDriverMajorVersion() 975 { 976 return DriverVersion.getDriverMajorVersion(); 977 } 978 979 980 985 public int getDriverMinorVersion() 986 { 987 return DriverVersion.getDriverMinorVersion(); 988 } 989 990 991 997 public String getDriverName() throws SQLException 998 { 999 return "InternetCDS Type 4 JDBC driver for MS SQLServer"; 1000 } 1001 1002 1003 1009 public String getDriverVersion() throws SQLException 1010 { 1011 return getDriverMajorVersion() + "." + getDriverMinorVersion(); 1012 } 1013 1014 1015 1083 public java.sql.ResultSet getExportedKeys(String catalog, String schema, 1084 String table) throws SQLException 1085 { 1086 NotImplemented(); return null; 1087 } 1088 1089 1090 1097 public String getExtraNameCharacters() throws SQLException 1098 { 1099 return "#$"; 1100 } 1101 1102 1103 1112 public String getIdentifierQuoteString() throws SQLException 1113 { 1114 return "\""; 1115 } 1116 1117 1118 1186 public java.sql.ResultSet getImportedKeys(String catalog, String schema, 1187 String table) throws SQLException 1188 { 1189 NotImplemented(); return null; 1190 } 1191 1192 1193 1245 public java.sql.ResultSet getIndexInfo(String catalog, String schema, String table, 1246 boolean unique, boolean approximate) 1247 throws SQLException 1248 { 1249 NotImplemented(); return null; 1250 } 1251 1252 1253 1259 1265 public int getMaxBinaryLiteralLength() throws SQLException 1266 { 1267 1269 return 131072; } 1271 1272 1273 1279 public int getMaxCatalogNameLength() throws SQLException 1280 { 1281 NotImplemented(); return 0; 1282 } 1283 1284 1285 1291 public int getMaxCharLiteralLength() throws SQLException 1292 { 1293 1295 return 131072; } 1297 1298 1299 1305 public int getMaxColumnNameLength() throws SQLException 1306 { 1307 1309 return 30; } 1311 1312 1313 1319 public int getMaxColumnsInGroupBy() throws SQLException 1320 { 1321 1323 return 16; } 1325 1326 1327 1333 public int getMaxColumnsInIndex() throws SQLException 1334 { 1335 1337 return 16; 1340 } 1341 1342 1343 1349 public int getMaxColumnsInOrderBy() throws SQLException 1350 { 1351 1353 return 16; } 1355 1356 1357 1363 public int getMaxColumnsInSelect() throws SQLException 1364 { 1365 1367 return 4000; } 1369 1370 1371 1377 public int getMaxColumnsInTable() throws SQLException 1378 { 1379 return 250; } 1382 1383 1384 1390 public int getMaxConnections() throws SQLException 1391 { 1392 1394 return 32767; 1397 } 1398 1399 1400 1406 public int getMaxCursorNameLength() throws SQLException 1407 { 1408 1410 return 30; } 1412 1413 1414 1420 public int getMaxIndexLength() throws SQLException 1421 { 1422 1424 return 900; } 1426 1427 1428 1434 public int getMaxProcedureNameLength() throws SQLException 1435 { 1436 1438 return 36; } 1440 1441 1442 1448 public int getMaxRowSize() throws SQLException 1449 { 1450 1452 return 1962; 1455 } 1456 1457 1458 1464 public int getMaxSchemaNameLength() throws SQLException 1465 { 1466 NotImplemented(); return 0; 1467 } 1468 1469 1470 1476 public int getMaxStatementLength() throws SQLException 1477 { 1478 1480 return 0x20000; 1483 } 1484 1485 1486 1493 public int getMaxStatements() throws SQLException 1494 { 1495 1499 return 32767; 1502 } 1503 1504 1505 1511 public int getMaxTableNameLength() throws SQLException 1512 { 1513 1515 return 30; } 1517 1518 1519 1525 public int getMaxTablesInSelect() throws SQLException 1526 { 1527 1529 return 16; } 1531 1532 1533 1539 public int getMaxUserNameLength() throws SQLException 1540 { 1541 return 30; 1543 } 1544 1545 1546 1552 public String getNumericFunctions() throws SQLException 1553 { 1554 return "ABS,ACOS,ASIN,ATAN,ATN2,CEILING,COS,COT," 1556 + "DEGREES,EXP,FLOOR,LOG,LOG10,PI,POWER,RADIANS," 1557 + "RAND,ROUND,SIGN,SIN,SQRT,TAN"; 1558 } 1559 1560 1561 1583 public java.sql.ResultSet getPrimaryKeys(String catalog, String schema, 1584 String table) throws SQLException 1585 { 1586 NotImplemented(); return null; 1587 } 1588 1589 1590 1646 public java.sql.ResultSet getProcedureColumns( 1647 String catalog, 1648 String schemaPattern, 1649 String procedureNamePattern, 1650 String columnNamePattern) 1651 throws SQLException 1652 { 1653 NotImplemented(); return null; 1654 } 1655 1656 1657 1691 public java.sql.ResultSet getProcedures(String catalog, 1692 String schemaPattern, 1693 String procedureNamePattern) 1694 throws SQLException 1695 { 1696 debugPrintln("Inside of getProcedures"); 1697 debugPrintln(" catalog is |" + catalog + "|"); 1698 debugPrintln(" schemaPattern is " + schemaPattern); 1699 debugPrintln(" procedurePattern is " + procedureNamePattern); 1700 1701 schemaPattern = schemaPattern.trim(); 1702 1703 if (tds.getDatabaseProductName().indexOf("Microsoft") >= 0 1704 && tds.getDatabaseProductVersion().startsWith("7.")) 1705 { 1706 String query; 1707 1708 query = ("select PROCEDURE_CAT=?, " 1709 + " PROCEDURE_SCHEM=substring(u.name, 1, 32), " 1710 + " PROCEDURE_NAME=substring(o.name, 1, 32), " 1711 + " '', '', '', " 1712 + " REMARKS='', PROCEDURE_TYPE=" 1713 + java.sql.DatabaseMetaData.procedureResultUnknown 1714 + " from "); 1715 if (catalog != null && (!catalog.equals(""))) 1716 { 1717 query = query + catalog + "."; 1719 } 1720 query = query + "dbo.sysobjects o, "; 1721 1722 if (catalog != null && (!catalog.equals(""))) 1723 { 1724 query = query + catalog + "."; 1726 } 1727 query = query + "dbo.sysusers u "; 1728 1729 query = query + " where o.uid=u.uid and xtype='P' "; 1730 query = query + " and u.name like ? "; query = query + " and o.name like ? "; 1733 debugPrintln("Query is |" + query + "|"); 1734 1735 java.sql.PreparedStatement ps = connection.prepareStatement(query); 1736 1737 debugPrintln("ps.setString(1, \"" + catalog + "\")"); 1738 ps.setString(1, catalog); 1739 if (schemaPattern==null || schemaPattern.equals("")) 1740 { 1741 debugPrintln("ps.setString(2, \"%\");"); 1742 ps.setString(2, "%"); 1743 } 1744 else 1745 { 1746 debugPrintln("ps.setString(2, \"" + schemaPattern + "\")"); 1747 ps.setString(2, schemaPattern); 1748 } 1749 if (procedureNamePattern==null || procedureNamePattern.equals("")) 1750 { 1751 debugPrintln("ps.setString(3, \"%\");"); 1752 ps.setString(3, "%"); 1753 } 1754 else 1755 { 1756 debugPrintln("ps.setString(3, \"" + procedureNamePattern + "\")"); 1757 ps.setString(3, procedureNamePattern); 1758 } 1759 1760 java.sql.ResultSet rs = ps.executeQuery(); 1761 1762 return rs; 1763 } 1764 else 1765 { 1766 NotImplemented(); return null; 1767 } 1768 } 1769 1770 1771 1777 public String getProcedureTerm() throws SQLException 1778 { 1779 1781 return "stored procedure"; 1783 } 1784 1785 1786 1799 public java.sql.ResultSet getSchemas() throws SQLException 1800 { 1801 String tmpName = "#t#" + UniqueId.getUniqueId(); 1803 final String sql = 1804 " create table " + tmpName + " " + 1805 " ( " + 1806 " q char(30) null, " + 1807 " o char(30) not null, " + 1808 " n char(30) null, " + 1809 " t char(30) null, " + 1810 " r varchar(255) null " + 1811 " ) " + 1812 " " + 1813 " insert into " + tmpName + " EXEC sp_tables ' ', '%', ' ', null " + 1814 " " + 1815 " select TABLE_SCHEM=o from " + tmpName + " " + 1816 ""; 1817 java.sql.Statement stmt = connection.createStatement(); 1818 java.sql.ResultSet rs; 1819 1820 1821 if (stmt.execute(sql)) 1822 { 1823 throw new SQLException("Internal error. " 1824 + "Unexpected result from stmt.execute(sql) " 1825 + "inside of getSchemas"); 1826 } 1827 1828 if (stmt.getMoreResults()) 1829 { 1830 throw new SQLException("Internal error. " 1831 + "Was expecting an update count " 1832 + "inside of getSchemas"); 1833 } 1834 else 1835 { 1836 int updateCount = stmt.getUpdateCount(); 1837 } 1838 1839 if (! stmt.getMoreResults()) 1840 { 1841 throw new SQLException("Internal error. " 1842 + "Was expecting an result set " 1843 + "inside of getSchemas"); 1844 } 1845 else 1846 { 1847 rs = stmt.getResultSet(); 1848 } 1849 1850 return rs; 1851 } 1852 1853 1854 1860 public String getSchemaTerm() throws SQLException 1861 { 1862 return "owner"; 1864 } 1865 1866 1867 1878 public String getSearchStringEscape() throws SQLException 1879 { 1880 1882 return "\\"; } 1884 1885 1886 1893 public String getSQLKeywords() throws SQLException 1894 { 1895 NotImplemented(); return null; 1896 } 1897 1898 1899 1905 public String getStringFunctions() throws SQLException 1906 { 1907 return "LTRIM,SOUNDEX,ASCII,PATINDEX,SPACE,CHAR,REPLICATE," 1908 + "STR,CHARINDEX,REVERSE,STUFF,DIFFERENCE,RIGHT," 1909 + "SUBSTRING,LOWER,RTRIM,UPPER"; 1910 } 1911 1912 1913 1919 public String getSystemFunctions() throws SQLException 1920 { 1921 return 1922 "COALESCE," + 1923 "COL_LENGTH," + 1924 "COL_NAME," + 1925 "DATALENGTH," + 1926 "DB_ID," + 1927 "DB_NAME," + 1928 "GETANSINULL," + 1929 "HOST_ID," + 1930 "HOST_NAME," + 1931 "IDENT_INCR," + 1932 "IDENT_SEED," + 1933 "INDEX_COL," + 1934 "ISNULL," + 1935 "NULLIF," + 1936 "OBJECT_ID," + 1937 "OBJECT_NAME," + 1938 "STATS_DATE," + 1939 "SUSER_ID," + 1940 "SUSER_NAME," + 1941 "USER_ID," + 1942 "USER_NAME"; 1943 } 1944 1945 1946 1979 public java.sql.ResultSet getTablePrivileges( 1980 String catalog, 1981 String schemaPattern, 1982 String tableNamePattern) throws SQLException 1983 { 1984 NotImplemented(); return null; 1985 } 1986 1987 1988 2019 public java.sql.ResultSet getTables( 2020 String catalog, 2021 String schemaPattern, 2022 String tableNamePattern, 2023 String types[]) 2024 throws SQLException 2025 { 2026 int paramIndex; 2027 int i; 2028 2029 2030 String sql = null; 2031 java.sql.Statement tmpTableStmt = connection.createStatement(); 2032 2033 String tmpTableName = "##t#" + UniqueId.getUniqueId(); 2037 String catalogCriteria; 2038 String schemaCriteria; 2039 String tableCriteria; 2040 String typesCriteria; 2041 2042 if (schemaPattern != null) 2043 { 2044 schemaPattern = schemaPattern.trim(); 2045 } 2046 if (tableNamePattern != null) 2047 { 2048 tableNamePattern = tableNamePattern.trim(); 2049 } 2050 2051 debugPrintln("inside getTables"); 2052 debugPrintln(" catalog is |" + catalog + "|"); 2053 debugPrintln(" schemaPattern is |" + schemaPattern + "|"); 2054 debugPrintln(" tableNamePattern is |" + tableNamePattern + "|"); 2055 if (types == null) 2056 { 2057 System.out.println("types is null"); 2058 } 2059 else 2060 { 2061 for(i=0; i<types.length; i++) 2062 { 2063 debugPrintln(" types[" + i + "] is |" + types[i]); 2064 } 2065 } 2066 2067 2068 sql = 2070 "create table " + tmpTableName + " ( " + 2071 " cat char(32) null, " + 2072 " schem char(32) null, " + 2073 " name char(32) null, " + 2074 " type char(32) null, " + 2075 " rem char(255) null) "; 2076 tmpTableStmt.execute(sql); 2077 2078 java.sql.ResultSet rs = getCatalogs(); 2082 while(rs.next()) 2083 { 2084 String cat = rs.getString(1); 2085 2086 sql = 2087 "insert into " + tmpTableName + " " + 2088 " select '" + cat + "', USER_NAME(uid), name, type, null " + 2089 " from " + cat + ".dbo.sysobjects " + 2090 " where type in ('S', 'U', 'V') "; 2091 try 2092 { 2093 tmpTableStmt.executeUpdate(sql); 2094 } 2095 catch (SQLException e) 2096 { 2097 } 2100 } 2101 rs.close(); 2102 2103 sql = 2104 "update " + tmpTableName + " " + 2105 " set type='SYSTEM TABLE' where type='S'"; 2106 tmpTableStmt.executeUpdate(sql); 2107 2108 sql = 2109 "update " + tmpTableName + " " + 2110 " set type='TABLE' where type='U'"; 2111 tmpTableStmt.executeUpdate(sql); 2112 2113 sql = 2114 "update " + tmpTableName + " " + 2115 " set type='VIEW' where type='V'"; 2116 tmpTableStmt.executeUpdate(sql); 2117 2118 if (catalog == null) 2119 { 2120 catalog = ""; 2121 catalogCriteria = " (cat like '%' or cat=?) "; 2122 } 2123 else 2124 { 2125 catalogCriteria = " cat=? "; 2126 } 2127 if (schemaPattern == null) 2128 { 2129 schemaPattern = "%"; 2130 } 2131 if (tableNamePattern == null) 2132 { 2133 tableNamePattern = "%"; 2134 } 2135 2136 2137 sql = 2138 "select TABLE_CAT=cat, TABLE_SCHEM=schem, " 2139 + " TABLE_NAME=name, TABLE_TYPE=type, " 2140 + " REMARKS=rem " 2141 + " from " + tmpTableName 2142 + " where " + catalogCriteria + " and " 2143 + " schem like ? and " 2144 + " name like ? "; 2145 if (types != null && types.length>0) 2146 { 2147 sql = sql + " and ( type = ? "; 2148 2149 for(i=1; i<types.length; i++) 2150 { 2151 sql = sql + " or type=? "; 2152 } 2153 sql = sql + " )"; 2154 } 2155 2156 java.sql.PreparedStatement ps = connection.prepareStatement(sql); 2157 2158 2159 ps.setString(1, catalog); 2160 ps.setString(2, schemaPattern); 2161 ps.setString(3, tableNamePattern); 2162 for(i=0; types!=null && i<types.length; i++) 2163 { 2164 ps.setString(i+4, types[i]); 2165 } 2166 rs = ps.executeQuery(); 2167 2168 tmpTableStmt.close(); 2170 2171 return rs; 2172 } 2173 2174 2175 2190 public java.sql.ResultSet getTableTypes() throws SQLException 2191 { 2192 String sql = 2194 "select 'TABLE' TABLE_TYPE " + 2195 "union select 'VIEW' TABLE_TYPE " + 2196 "union select 'SYSTEM TABLE' TABLE_TYPE "; 2197 java.sql.Statement stmt = connection.createStatement(); 2198 java.sql.ResultSet rs = stmt.executeQuery(sql); 2199 2200 return rs; 2201 } 2202 2203 2204 2210 public String getTimeDateFunctions() throws SQLException 2211 { 2212 return "GETDATE,DATEPART,DATENAME,DATEDIFF,DATEADD"; 2213 } 2214 2215 2216 2262 public java.sql.ResultSet getTypeInfo() throws SQLException 2263 { 2264 NotImplemented(); return null; 2265 } 2266 2267 2268 2274 public String getURL() throws SQLException 2275 { 2276 return ((ConnectionHelper)connection).getUrl(); 2277 } 2278 2279 2280 2286 public String getUserName() throws SQLException 2287 { 2288 java.sql.Statement s = null; 2289 java.sql.ResultSet rs = null; 2290 String result = ""; 2291 2292 try 2293 { 2294 s = connection.createStatement(); 2295 rs = s.executeQuery("select USER_NAME()"); 2297 2298 if (! rs.next()) 2299 { 2300 throw new SQLException("Couldn't determine user name"); 2301 } 2302 result = rs.getString(1); 2303 } 2304 finally 2305 { 2306 if (rs != null) 2307 { 2308 rs.close(); 2309 } 2310 if (s != null) 2311 { 2312 s.close(); 2313 } 2314 } 2315 return result; 2316 } 2317 2318 2319 2349 public java.sql.ResultSet getVersionColumns(String catalog, String schema, 2350 String table) throws SQLException 2351 { 2352 NotImplemented(); return null; 2353 } 2354 2355 2356 2363 public boolean isCatalogAtStart() throws SQLException 2364 { 2365 return true; 2366 } 2367 2368 2369 2375 public boolean isReadOnly() throws SQLException 2376 { 2377 NotImplemented(); return false; 2378 } 2379 2380 2381 2389 public boolean nullPlusNonNullIsNull() throws SQLException 2390 { 2391 2393 return false; 2396 } 2397 2398 2399 2405 public boolean nullsAreSortedAtEnd() throws SQLException 2406 { 2407 2409 return false; 2411 } 2412 2413 2414 2420 public boolean nullsAreSortedAtStart() throws SQLException 2421 { 2422 2424 return true; 2426 } 2427 2428 2429 2435 public boolean nullsAreSortedHigh() throws SQLException 2436 { 2437 2439 return false; 2441 } 2442 2443 2444 2450 public boolean nullsAreSortedLow() throws SQLException 2451 { 2452 2454 return false; 2456 } 2457 2458 2459 2466 public boolean storesLowerCaseIdentifiers() throws SQLException 2467 { 2468 NotImplemented(); return false; 2471 } 2472 2473 2474 2481 public boolean storesLowerCaseQuotedIdentifiers() throws SQLException 2482 { 2483 NotImplemented(); return false; 2484 } 2485 2486 2487 2494 public boolean storesMixedCaseIdentifiers() throws SQLException 2495 { 2496 NotImplemented(); return false; 2497 } 2498 2499 2500 2507 public boolean storesMixedCaseQuotedIdentifiers() throws SQLException 2508 { 2509 NotImplemented(); return false; 2510 } 2511 2512 2513 2520 public boolean storesUpperCaseIdentifiers() throws SQLException 2521 { 2522 NotImplemented(); return false; 2523 } 2524 2525 2526 2533 public boolean storesUpperCaseQuotedIdentifiers() throws SQLException 2534 { 2535 NotImplemented(); return false; 2536 } 2537 2538 2539 2542 2548 public boolean supportsAlterTableWithAddColumn() throws SQLException 2549 { 2550 return true; 2551 } 2552 2553 2554 2560 public boolean supportsAlterTableWithDropColumn() throws SQLException 2561 { 2562 return false; 2563 } 2564 2565 2566 2574 public boolean supportsANSI92EntryLevelSQL() throws SQLException 2575 { 2576 NotImplemented(); return false; 2577 } 2578 2579 2580 2586 public boolean supportsANSI92FullSQL() throws SQLException 2587 { 2588 NotImplemented(); return false; 2589 } 2590 2591 2592 2598 public boolean supportsANSI92IntermediateSQL() throws SQLException 2599 { 2600 NotImplemented(); return false; 2601 } 2602 2603 2604 2610 public boolean supportsCatalogsInDataManipulation() throws SQLException 2611 { 2612 NotImplemented(); return false; 2613 } 2614 2615 2616 2622 public boolean supportsCatalogsInIndexDefinitions() throws SQLException 2623 { 2624 NotImplemented(); return false; 2625 } 2626 2627 2628 2634 public boolean supportsCatalogsInPrivilegeDefinitions() throws SQLException 2635 { 2636 NotImplemented(); return false; 2637 } 2638 2639 2640 2646 public boolean supportsCatalogsInProcedureCalls() throws SQLException 2647 { 2648 NotImplemented(); return false; 2649 } 2650 2651 2652 2658 public boolean supportsCatalogsInTableDefinitions() throws SQLException 2659 { 2660 NotImplemented(); return false; 2661 } 2662 2663 2664 2676 public boolean supportsColumnAliasing() throws SQLException 2677 { 2678 return true; 2679 } 2680 2681 2682 2688 public boolean supportsConvert() throws SQLException 2689 { 2690 return true; 2691 } 2692 2693 2694 2703 public boolean supportsConvert(int fromType, int toType) throws SQLException 2704 { 2705 NotImplemented(); return false; 2706 } 2707 2708 2709 2715 public boolean supportsCoreSQLGrammar() throws SQLException 2716 { 2717 NotImplemented(); return false; 2718 } 2719 2720 2721 2729 public boolean supportsCorrelatedSubqueries() throws SQLException 2730 { 2731 NotImplemented(); return false; 2732 } 2733 2734 2735 2742 public boolean supportsDataDefinitionAndDataManipulationTransactions() 2743 throws SQLException 2744 { 2745 NotImplemented(); return false; 2746 } 2747 2748 2749 2756 public boolean supportsDataManipulationTransactionsOnly() 2757 throws SQLException 2758 { 2759 NotImplemented(); return false; 2760 } 2761 2762 2763 2770 public boolean supportsDifferentTableCorrelationNames() throws SQLException 2771 { 2772 NotImplemented(); return false; 2773 } 2774 2775 2776 2782 public boolean supportsExpressionsInOrderBy() throws SQLException 2783 { 2784 NotImplemented(); return false; 2785 } 2786 2787 2788 2794 public boolean supportsExtendedSQLGrammar() throws SQLException 2795 { 2796 NotImplemented(); return false; 2797 } 2798 2799 2800 2806 public boolean supportsFullOuterJoins() throws SQLException 2807 { 2808 2810 return true; } 2812 2813 2814 2820 public boolean supportsGroupBy() throws SQLException 2821 { 2822 return true; 2823 } 2824 2825 2826 2833 public boolean supportsGroupByBeyondSelect() throws SQLException 2834 { 2835 2837 return true; } 2839 2840 2841 2847 public boolean supportsGroupByUnrelated() throws SQLException 2848 { 2849 return true; 2851 } 2852 2853 2854 2860 public boolean supportsIntegrityEnhancementFacility() throws SQLException 2861 { 2862 NotImplemented(); return false; 2863 } 2864 2865 2866 2874 public boolean supportsLikeEscapeClause() throws SQLException 2875 { 2876 2878 return true; } 2880 2881 2882 2889 public boolean supportsLimitedOuterJoins() throws SQLException 2890 { 2891 return true; 2892 } 2893 2894 2895 2903 public boolean supportsMinimumSQLGrammar() throws SQLException 2904 { 2905 NotImplemented(); return false; 2906 } 2907 2908 2909 2918 public boolean supportsMixedCaseIdentifiers() throws SQLException 2919 { 2920 NotImplemented(); return false; 2921 } 2922 2923 2924 2933 public boolean supportsMixedCaseQuotedIdentifiers() throws SQLException 2934 { 2935 NotImplemented(); return false; 2936 } 2937 2938 2939 2945 public boolean supportsMultipleResultSets() throws SQLException 2946 { 2947 return true; 2948 } 2949 2950 2951 2958 public boolean supportsMultipleTransactions() throws SQLException 2959 { 2960 return true; 2961 } 2962 2963 2964 2972 public boolean supportsNonNullableColumns() throws SQLException 2973 { 2974 return true; 2975 } 2976 2977 2978 2984 public boolean supportsOpenCursorsAcrossCommit() throws SQLException 2985 { 2986 NotImplemented(); return false; 2987 } 2988 2989 2990 2996 public boolean supportsOpenCursorsAcrossRollback() throws SQLException 2997 { 2998 NotImplemented(); return false; 2999 } 3000 3001 3002 3009 public boolean supportsOpenStatementsAcrossCommit() throws SQLException 3010 { 3011 NotImplemented(); return false; 3012 } 3013 3014 3015 3022 public boolean supportsOpenStatementsAcrossRollback() throws SQLException 3023 { 3024 NotImplemented(); return false; 3025 } 3026 3027 3028 3034 public boolean supportsOrderByUnrelated() throws SQLException 3035 { 3036 return true; 3038 } 3039 3040 3041 3047 public boolean supportsOuterJoins() throws SQLException 3048 { 3049 return true; 3050 } 3051 3052 3053 3059 public boolean supportsPositionedDelete() throws SQLException 3060 { 3061 return false; 3063 } 3064 3065 3066 3072 public boolean supportsPositionedUpdate() throws SQLException 3073 { 3074 return false; 3076 } 3077 3078 3079 3085 public boolean supportsSchemasInDataManipulation() throws SQLException 3086 { 3087 NotImplemented(); return false; 3088 } 3089 3090 3091 3097 public boolean supportsSchemasInIndexDefinitions() throws SQLException 3098 { 3099 NotImplemented(); return false; 3100 } 3101 3102 3103 3109 public boolean supportsSchemasInPrivilegeDefinitions() throws SQLException 3110 { 3111 NotImplemented(); return false; 3112 } 3113 3114 3115 3121 public boolean supportsSchemasInProcedureCalls() throws SQLException 3122 { 3123 NotImplemented(); return false; 3124 } 3125 3126 3127 3133 public boolean supportsSchemasInTableDefinitions() throws SQLException 3134 { 3135 NotImplemented(); return false; 3136 } 3137 3138 3139 3145 public boolean supportsSelectForUpdate() throws SQLException 3146 { 3147 NotImplemented(); return false; 3148 } 3149 3150 3151 3158 public boolean supportsStoredProcedures() throws SQLException 3159 { 3160 NotImplemented(); return false; 3161 } 3162 3163 3164 3172 public boolean supportsSubqueriesInComparisons() throws SQLException 3173 { 3174 return true; 3175 } 3176 3177 3178 3186 public boolean supportsSubqueriesInExists() throws SQLException 3187 { 3188 return true; 3189 } 3190 3191 3192 3200 public boolean supportsSubqueriesInIns() throws SQLException 3201 { 3202 return true; 3203 } 3204 3205 3206 3214 public boolean supportsSubqueriesInQuantifieds() throws SQLException 3215 { 3216 NotImplemented(); return false; 3217 } 3218 3219 3220 3228 public boolean supportsTableCorrelationNames() throws SQLException 3229 { 3230 return true; 3231 } 3232 3233 3234 3242 public boolean supportsTransactionIsolationLevel(int level) 3243 throws SQLException 3244 { 3245 return true; 3246 } 3247 3248 3249 3256 public boolean supportsTransactions() throws SQLException 3257 { 3258 return true; 3259 } 3260 3261 3262 3268 public boolean supportsUnion() throws SQLException 3269 { 3270 return true; 3271 } 3272 3273 3274 3280 public boolean supportsUnionAll() throws SQLException 3281 { 3282 return true; 3283 } 3284 3285 3286 3292 public boolean usesLocalFilePerTable() throws SQLException 3293 { 3294 return false; 3295 } 3296 3297 3298 3304 public boolean usesLocalFiles() throws SQLException 3305 { 3306 return false; 3307 } 3308 3309 3311 3321 public boolean supportsResultSetType(int type) throws SQLException 3322 { 3323 NotImplemented(); 3324 return false; 3325 } 3326 3327 3328 3340 public boolean supportsResultSetConcurrency(int type, int concurrency) 3341 throws SQLException 3342 { 3343 NotImplemented(); 3344 return false; 3345 } 3346 3347 3357 public boolean ownUpdatesAreVisible(int type) throws SQLException 3358 { 3359 NotImplemented(); 3360 return false; 3361 } 3362 3363 3373 public boolean ownDeletesAreVisible(int type) throws SQLException 3374 { 3375 NotImplemented(); 3376 return false; 3377 } 3378 3388 public boolean ownInsertsAreVisible(int type) throws SQLException 3389 { 3390 NotImplemented(); 3391 return false; 3392 } 3393 3394 3405 public boolean othersUpdatesAreVisible(int type) throws SQLException 3406 { 3407 NotImplemented(); 3408 return false; 3409 } 3410 3411 3422 public boolean othersDeletesAreVisible(int type) throws SQLException 3423 { 3424 NotImplemented(); 3425 return false; 3426 } 3427 3428 3440 public boolean othersInsertsAreVisible(int type) throws SQLException 3441 { 3442 NotImplemented(); 3443 return false; 3444 } 3445 3446 3457 public boolean updatesAreDetected(int type) throws SQLException 3458 { 3459 NotImplemented(); 3460 return false; 3461 } 3462 3463 3474 public boolean deletesAreDetected(int type) throws SQLException 3475 { 3476 NotImplemented(); 3477 return false; 3478 } 3479 3480 3490 public boolean insertsAreDetected(int type) throws SQLException 3491 { 3492 NotImplemented(); 3493 return false; 3494 } 3495 3496 3502 public boolean supportsBatchUpdates() throws SQLException 3503 { 3504 NotImplemented(); 3505 return false; 3506 } 3507 3508 3546 public java.sql.ResultSet getUDTs(String catalog, String schemaPattern, 3547 String typeNamePattern, int[] types) 3548 throws SQLException 3549 { 3550 NotImplemented(); 3551 return null; 3552 } 3553 3554 3560 public java.sql.Connection getConnection() throws SQLException 3561 { 3562 return connection; 3563 } 3564 3565 3566 public boolean supportsSavepoints() throws SQLException { 3567 throw new UnsupportedOperationException ("ResultSet.updateArray(String,java.sql.Array) unsupported"); 3568 } 3569 3570 public boolean supportsNamedParameters() throws SQLException { 3571 throw new UnsupportedOperationException ("ResultSet.updateArray(String,java.sql.Array) unsupported"); 3572 } 3573 3574 public boolean supportsMultipleOpenResults() throws SQLException { 3575 throw new UnsupportedOperationException ("ResultSet.updateArray(String,java.sql.Array) unsupported"); 3576 } 3577 3578 public boolean supportsGetGeneratedKeys() throws SQLException { 3579 throw new UnsupportedOperationException ("ResultSet.updateArray(String,java.sql.Array) unsupported"); 3580 } 3581 3582 public ResultSet getSuperTypes(java.lang.String str1,java.lang.String str2,java.lang.String str3) throws SQLException { 3583 throw new UnsupportedOperationException ("ResultSet.updateArray(String,java.sql.Array) unsupported"); 3584 } 3585 3586 public ResultSet getSuperTables(java.lang.String str1,java.lang.String str2,java.lang.String str3) throws SQLException { 3587 throw new UnsupportedOperationException ("ResultSet.updateArray(String,java.sql.Array) unsupported"); 3588 } 3589 3590 public ResultSet getAttributes(java.lang.String str1,java.lang.String str2,java.lang.String str3, String str4) throws SQLException { 3591 throw new UnsupportedOperationException ("ResultSet.updateArray(String,java.sql.Array) unsupported"); 3592 } 3593 3594 public boolean supportsResultSetHoldability(int x) throws SQLException { 3595 throw new UnsupportedOperationException ("ResultSet.updateArray(String,java.sql.Array) unsupported"); 3596 } 3597 3598 public boolean supportsResultSetHoldability() throws SQLException { 3599 throw new UnsupportedOperationException ("ResultSet.updateArray(String,java.sql.Array) unsupported"); 3600 } 3601 3602 public int getResultSetHoldability() throws SQLException { 3603 throw new UnsupportedOperationException ("ResultSet.updateArray(String,java.sql.Array) unsupported"); 3604 } 3605 3606 public int getDatabaseMajorVersion() throws SQLException { 3607 throw new UnsupportedOperationException ("ResultSet.updateArray(String,java.sql.Array) unsupported"); 3608 } 3609 3610 public int getDatabaseMinorVersion() throws SQLException { 3611 throw new UnsupportedOperationException ("ResultSet.updateArray(String,java.sql.Array) unsupported"); 3612 } 3613 3614 public int getJDBCMajorVersion() throws SQLException { 3615 throw new UnsupportedOperationException ("ResultSet.updateArray(String,java.sql.Array) unsupported"); 3616 } 3617 3618 public int getJDBCMinorVersion() throws SQLException { 3619 throw new UnsupportedOperationException ("ResultSet.updateArray(String,java.sql.Array) unsupported"); 3620 } 3621 3622 public int getSQLStateType() throws SQLException { 3623 throw new UnsupportedOperationException ("ResultSet.updateArray(String,java.sql.Array) unsupported"); 3624 } 3625 3626 public boolean locatorsUpdateCopy() throws SQLException { 3627 throw new UnsupportedOperationException ("ResultSet.updateArray(String,java.sql.Array) unsupported"); 3628 } 3629 3630 public boolean supportsStatementPooling() throws SQLException { 3631 throw new UnsupportedOperationException ("ResultSet.updateArray(String,java.sql.Array) unsupported"); 3632 } 3633 3634 3635 public static void main(String args[]) 3636 throws java.lang.ClassNotFoundException , 3637 java.sql.SQLException , 3638 java.lang.IllegalAccessException , 3639 java.lang.InstantiationException 3640 { 3641 String url = "jdbc:freetds://kap/jdbctest"; 3642 String user = "testuser"; 3643 String password = "password"; 3644 3645 Class.forName("com.internetcds.jdbc.tds.Driver").newInstance(); 3646 java.sql.Connection cx = DriverManager.getConnection(url, user, password); 3647 java.sql.DatabaseMetaData m = cx.getMetaData(); 3648 java.sql.ResultSet rs; 3649 3650 System.out.println("Connected to " + url + " as " + user); 3651 3652 System.out.println("url is " + m.getURL()); 3653 System.out.println("username is " + m.getUserName()); 3654 3655 System.out.println(m.getDriverName()); 3656 3657 System.out.println("Getting columns"); 3658 rs = m.getColumns(null, "%", "%", "%"); 3659 System.out.println("Got columns"); 3660 while(rs.next()) 3661 { 3662 System.out.println( 3663 "TABLE_CAT: " + rs.getString("TABLE_CAT") + "\n" + 3664 "TABLE_SCHEM: " + rs.getString("TABLE_SCHEM") + "\n" + 3665 "TABLE_NAME: " + rs.getString("TABLE_NAME") + "\n" + 3666 "COLUMN_NAME: " + rs.getString("COLUMN_NAME") + "\n" + 3667 "DATA_TYPE: " + rs.getString("DATA_TYPE") + "\n" + 3668 "TYPE_NAME: " + rs.getString("TYPE_NAME") + "\n" + 3669 "COLUMN_SIZE: " + rs.getString("COLUMN_SIZE") + "\n" + 3670 "BUFFER_LENGTH: " + rs.getString("BUFFER_LENGTH") + "\n" + 3671 "DECIMAL_DIGITS: " + rs.getString("DECIMAL_DIGITS") + "\n" + 3672 "NUM_PREC_RADIX: " + rs.getString("NUM_PREC_RADIX") + "\n" + 3673 "NULLABLE: " + rs.getString("NULLABLE") + "\n" + 3674 "REMARKS: " + rs.getString("REMARKS") + "\n" + 3675 "COLUMN_DEF: " + rs.getString("COLUMN_DEF") + "\n" + 3676 "SQL_DATA_TYPE: " + rs.getString("SQL_DATA_TYPE") + "\n" + 3677 "SQL_DATETIME_SUB: " + rs.getString("SQL_DATETIME_SUB") + "\n" + 3678 "CHAR_OCTET_LENGTH: " + rs.getString("CHAR_OCTET_LENGTH") + "\n" + 3679 "ORDINAL_POSITION: " + rs.getString("ORDINAL_POSITION") + "\n" + 3680 "IS_NULLABLE: " + rs.getString("IS_NULLABLE") + "\n" + 3681 "\n"); 3682 } 3683 System.out.println("\n"); 3684 rs.close(); 3685 3686 System.out.println("Catalog term- " + m.getCatalogTerm()); 3687 System.out.println("Catalog separator- " + m.getCatalogSeparator()); 3688 System.out.println("Catalog is " 3689 + (m.isCatalogAtStart() ? "" : "not ") 3690 + "at start"); 3691 System.out.println("Catalogs-"); 3692 rs = m.getCatalogs(); 3693 while(rs.next()) 3694 { 3695 System.out.println(" " + rs.getString(1)); 3696 } 3697 System.out.println("\n"); 3698 rs.close(); 3699 3700 System.out.println("Schema term- " + m.getSchemaTerm()); 3701 rs = m.getSchemas(); 3702 while(rs.next()) 3703 { 3704 System.out.println(" " + rs.getString(1)); 3705 } 3706 System.out.println("\n"); 3707 rs.close(); 3708 3709 System.out.println("Table types-"); 3710 rs = m.getTableTypes(); 3711 while(rs.next()) 3712 { 3713 System.out.println(" " + rs.getString(1)); 3714 } 3715 System.out.println("\n"); 3716 rs.close(); 3717 3718 System.out.println("Tables- "); 3719 rs = m.getTables(null, "%", "%", null); 3720 while(rs.next()) 3721 { 3722 System.out.println(" " + 3723 rs.getString(1) + 3724 "." + 3725 rs.getString(2) + 3726 "." + 3727 rs.getString(3) + 3728 "." + 3729 rs.getString(4) + 3730 "." + 3731 rs.getString(5) + 3732 ""); 3733 } 3734 System.out.println("\n"); 3735 rs.close(); 3736 3737 System.out.println("Tables for pubs- "); 3738 String tables[] = {"SYSTEM TABLE", "VIEW"}; 3739 rs = m.getTables("pubs", "%", "%", tables); 3740 while(rs.next()) 3741 { 3742 System.out.println(" " + 3743 rs.getString(1) + 3744 "." + 3745 rs.getString(2) + 3746 "." + 3747 rs.getString(3) + 3748 "." + 3749 rs.getString(4) + 3750 "." + 3751 rs.getString(5) + 3752 ""); 3753 } 3754 System.out.println("\n"); 3755 rs.close(); 3756 3757 3758 System.out.println("Columns- "); 3759 rs = m.getColumns(null, "%", "%", "%"); 3760 while(rs.next()) 3761 { 3762 System.out.println( 3763 "TABLE_CAT: " + rs.getString("TABLE_CAT") + "\n" + 3764 "TABLE_SCHEM: " + rs.getString("TABLE_SCHEM") + "\n" + 3765 "TABLE_NAME: " + rs.getString("TABLE_NAME") + "\n" + 3766 "COLUMN_NAME: " + rs.getString("COLUMN_NAME") + "\n" + 3767 "DATA_TYPE: " + rs.getString("DATA_TYPE") + "\n" + 3768 "TYPE_NAME: " + rs.getString("TYPE_NAME") + "\n" + 3769 "COLUMN_SIZE: " + rs.getString("COLUMN_SIZE") + "\n" + 3770 "BUFFER_LENGTH: " + rs.getString("BUFFER_LENGTH") + "\n" + 3771 "DECIMAL_DIGITS: " + rs.getString("DECIMAL_DIGITS") + "\n" + 3772 "NUM_PREC_RADIX: " + rs.getString("NUM_PREC_RADIX") + "\n" + 3773 "NULLABLE: " + rs.getString("NULLABLE") + "\n" + 3774 "REMARKS: " + rs.getString("REMARKS") + "\n" + 3775 "COLUMN_DEF: " + rs.getString("COLUMN_DEF") + "\n" + 3776 "SQL_DATA_TYPE: " + rs.getString("SQL_DATA_TYPE") + "\n" + 3777 "SQL_DATETIME_SUB: " + rs.getString("SQL_DATETIME_SUB") + "\n" + 3778 "CHAR_OCTET_LENGTH: " + rs.getString("CHAR_OCTET_LENGTH") + "\n" + 3779 "ORDINAL_POSITION: " + rs.getString("ORDINAL_POSITION") + "\n" + 3780 "IS_NULLABLE: " + rs.getString("IS_NULLABLE") + "\n" + 3781 "\n"); 3782 } 3783 System.out.println("\n"); 3784 rs.close(); 3785 3786 System.out.println("Done"); 3787 } 3788} 3789 | Popular Tags |