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 { Connection conn = getHSQLConnection(); DatabaseMetaData meta = conn.getMetaData(); ResultSet catalogs = meta.getCatalogs(); while (catalogs.next()) { String catalog = catalogs.getString(1); //"TABLE_CATALOG" System.out.println("catalog: " + catalog); }//from ww w . ja va 2 s .c o m conn.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { Connection conn = getHSQLConnection(); DatabaseMetaData meta = conn.getMetaData(); ResultSet schemas = meta.getSchemas(); while (schemas.next()) { String tableSchema = schemas.getString(1); // "TABLE_SCHEM" System.out.println("tableSchema:" + tableSchema); String tableCatalog = schemas.getString(2); //"TABLE_CATALOG" System.out.println("tableCatalog:" + tableCatalog); }/*from w w w. jav a 2 s . c om*/ conn.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { Connection conn = getHSQLConnection(); DatabaseMetaData meta = conn.getMetaData(); try {//from ww w . ja v a 2 s . com 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"); } conn.close(); }
From source file:Main.java
public static void main(String[] args) { try {/* www.j av a 2 s .c o m*/ Class.forName(driver); Connection conn = DriverManager.getConnection(url, username, password); System.out.println(conn.getMetaData().getDatabaseProductName()); } catch (Exception e) { e.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) throws Exception { Connection conn = getConnection(); DatabaseMetaData mtdt = conn.getMetaData(); ResultSet rs = mtdt.getTables(conn.getCatalog(), "%", "%", null); 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 . ja va 2 s. c o m 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 { Connection conn = getHSQLConnection(); DatabaseMetaData meta = conn.getMetaData(); int txisolation = meta.getDefaultTransactionIsolation(); System.out.println("Database default transaction isolation is " + txisolation + " (" + transactionIsolationToString(txisolation) + ")."); conn.close();/*from w w w .j a v a 2 s . c om*/ }
From source file:Main.java
public static void main(String[] args) throws Exception { Connection conn = getHSQLConnection(); DatabaseMetaData dbmd = conn.getMetaData(); ResultSet rs = dbmd.getTypeInfo(); while (rs.next()) { String typeName = rs.getString("TYPE_NAME"); short dataType = rs.getShort("DATA_TYPE"); String createParams = rs.getString("CREATE_PARAMS"); int nullable = rs.getInt("NULLABLE"); boolean caseSensitive = rs.getBoolean("CASE_SENSITIVE"); System.out.println("DBMS type " + typeName + ":"); System.out.println(" java.sql.Types: " + dataType); System.out.print(" parameters used to create: "); System.out.println(createParams); System.out.println(" nullable?: " + nullable); System.out.print(" case sensitive?: "); System.out.println(caseSensitive); System.out.println(""); }//from w w w . ja v a2 s.c om conn.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { Connection conn = getMySqlConnection(); DatabaseMetaData meta = conn.getMetaData(); try {//from w w w. ja v a 2 s . c om int majorVersion = meta.getDatabaseMajorVersion(); System.out.println("major Version: " + majorVersion); 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[] args) throws Exception { Connection conn = getConnection(); DatabaseMetaData mtdt = conn.getMetaData(); System.out.println(mtdt.getProcedureTerm()); ResultSet rs = mtdt.getProcedures(conn.getCatalog(), "%", "%"); 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 www . ja v a2 s .co m 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 { Connection conn = getConnection(); try {// w w w .j av a2 s . c o m DatabaseMetaData dbmd = conn.getMetaData(); if (dbmd == null) { System.out.println("No"); } if (dbmd.supportsStatementPooling()) { System.out.println("statement pooling is supported"); } else { System.out.println("No"); } } catch (Exception e) { e.printStackTrace(); } finally { conn.close(); } }