List of usage examples for java.sql Connection getMetaData
DatabaseMetaData getMetaData() throws SQLException;
DatabaseMetaData
object that contains metadata about the database to which this Connection
object represents a connection. From source file:Main.java
public static void main(String args[]) throws Exception { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); String URL = "jdbc:odbc:dbName"; Connection conn = DriverManager.getConnection(URL, "user", "passw"); DatabaseMetaData dmd = conn.getMetaData(); ResultSet rs1 = dmd.getSchemas(); while (rs1.next()) { String ss = rs1.getString(1); ResultSet rs2 = dmd.getTables(null, ss, "%", null); while (rs2.next()) System.out.println(rs2.getString(3) + " " + rs2.getString(4)); }/*from w w w .ja v a 2 s.c om*/ conn.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { Connection conn = getConnection(); DatabaseMetaData mtdt = conn.getMetaData(); // list catalogs managed by this dbms System.out.println(mtdt.getCatalogTerm()); ResultSet rs = mtdt.getCatalogs(); ResultSetMetaData rsmd = rs.getMetaData(); int numCols = rsmd.getColumnCount(); for (int i = 1; i <= numCols; i++) { if (i > 1) System.out.print(", "); System.out.print(rsmd.getColumnLabel(i)); }/*from w w w .j a v a 2 s . com*/ System.out.println(""); while (rs.next()) { for (int i = 1; i <= numCols; i++) { if (i > 1) System.out.print(", "); System.out.print(rs.getString(i)); } System.out.println(""); } conn.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { Class.forName("oracle.jdbc.driver.OracleDriver"); Connection conn = DriverManager.getConnection(url, username, password); DatabaseMetaData metadata = conn.getMetaData(); ResultSet result = metadata.getProcedures(null, "JAVA", "%"); while (result.next()) { System.out.println(result.getString("PROCEDURE_CAT") + " - " + result.getString("PROCEDURE_SCHEM") + " - " + result.getString("PROCEDURE_NAME")); }/*from w w w .j a v a 2 s .co m*/ }
From source file:Main.java
public static void main(String[] args) throws Exception { Class.forName(DRIVER);/*from w w w . ja v a 2 s . com*/ Connection connection = DriverManager.getConnection(URL, USERNAME, PASSWORD); DatabaseMetaData metadata = connection.getMetaData(); boolean isBatchingSupported = metadata.supportsBatchUpdates(); System.out.println("Batching Supported = " + isBatchingSupported); connection.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { Class.forName(DRIVER);/*from ww w . jav a 2 s. co m*/ Connection connection = DriverManager.getConnection(URL, USERNAME, PASSWORD); DatabaseMetaData metadata = connection.getMetaData(); boolean isSupportTransaction = metadata.supportsTransactions(); System.out.println("Support Transaction = " + isSupportTransaction); connection.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { Class.forName(DRIVER);//from w ww .j av a2 s . c o m Connection connection = DriverManager.getConnection(URL, USERNAME, PASSWORD); DatabaseMetaData metadata = connection.getMetaData(); int maxLength = metadata.getMaxTableNameLength(); System.out.println("Max Table Name Length = " + maxLength); connection.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { Class.forName(DRIVER);//from w w w . j a v a 2 s.c o m Connection connection = DriverManager.getConnection(URL, USERNAME, PASSWORD); DatabaseMetaData metadata = connection.getMetaData(); int maxConnection = metadata.getMaxConnections(); System.out.println("Maximum Connection = " + maxConnection); connection.close(); }
From source file:TestDatabaseMetaDataToolDatabaseInformation.java
public static void main(String[] args) throws Exception { Connection conn = getMySqlConnection(); DatabaseMetaData meta = conn.getMetaData(); // Oracle (and some other vendors) do not support // some the following methods; therefore, we need // to use try-catch block. try {/*from w w w . j a v a2 s . co m*/ int majorVersion = meta.getDatabaseMajorVersion(); System.out.println("major Version: " + majorVersion); } catch (Exception e) { System.out.println("major Version: unsupported feature"); } try { int minorVersion = meta.getDatabaseMinorVersion(); System.out.println("minorVersion" + minorVersion); } catch (Exception e) { System.out.println("minorVersion unsupported feature"); } String productName = meta.getDatabaseProductName(); String productVersion = meta.getDatabaseProductVersion(); System.out.println("productName" + productName); System.out.println("productVersion" + productVersion); conn.close(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { String driverName = "com.jnetdirect.jsql.JSQLDriver"; Class.forName(driverName);//from w ww. j av a 2s. co m String serverName = "127.0.0.1"; String portNumber = "1433"; String mydatabase = serverName + ":" + portNumber; String url = "jdbc:JSQLConnect://" + mydatabase; String username = "username"; String password = "password"; Connection connection = DriverManager.getConnection(url, username, password); DatabaseMetaData dbmd = connection.getMetaData(); String[] keywords = dbmd.getSQLKeywords().split(",\\s*"); Arrays.toString(keywords); }
From source file:Main.java
public static void main(String[] args) throws Exception { Class.forName(DRIVER);/*from w ww . ja va 2 s. c o m*/ Connection connection = DriverManager.getConnection(URL, USERNAME, PASSWORD); DatabaseMetaData metadata = connection.getMetaData(); boolean updatable = metadata.supportsResultSetConcurrency(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE); System.out.println("Updatable ResultSet supported = " + updatable); connection.close(); }