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[] argv) throws Exception { String driverName = "com.jnetdirect.jsql.JSQLDriver"; Class.forName(driverName);//from www .jav a 2 s. c o 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(); // Get all stored procedures in any schema and catalog ResultSet resultSet = dbmd.getProcedures(null, null, "%"); // Get stored procedure names from the result set while (resultSet.next()) { String procName = resultSet.getString(3); System.out.println(procName); } }
From source file:Main.java
public static void main(String[] args) throws Exception { Class.forName(DRIVER);/* w w w .j av a 2s . c o m*/ Connection connection = DriverManager.getConnection(URL, USERNAME, PASSWORD); DatabaseMetaData metadata = connection.getMetaData(); int majorVersion = metadata.getDatabaseMajorVersion(); System.out.println("majorVersion = " + majorVersion); int minorVersion = metadata.getDatabaseMinorVersion(); System.out.println("minorVersion = " + minorVersion); String productName = metadata.getDatabaseProductName(); System.out.println("productName = " + productName); String productVersion = metadata.getDatabaseProductVersion(); System.out.println("productVersion = " + productVersion); connection.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 . ja va 2 s. c om 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[] types = { "TABLE" }; ResultSet resultSet = dbmd.getTables(null, null, "%", types); while (resultSet.next()) { String tableName = resultSet.getString(3); String tableCatalog = resultSet.getString(1); String tableSchema = resultSet.getString(2); } }
From source file:JDBCVersionApp.java
public static void main(String args[]) throws ClassNotFoundException, SQLException { Class.forName("oracle.jdbc.driver.OracleDriver"); Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@dssnt01:1521:dssora01", "scott", "tiger"); DatabaseMetaData meta = conn.getMetaData(); System.out.println("You're using version: " + meta.getDriverVersion() + " of the Oracle JDBC driver."); conn.close();//from w w w.j av a 2 s. c om }
From source file:Test.java
public static void main(String[] args) throws Exception { Connection con = DriverManager.getConnection("jdbc:derby://localhost:1527/contact", "userName", "password"); DatabaseMetaData metaData = con.getMetaData(); ResultSet resultSet = metaData.getPseudoColumns("", "schemaName", "tableName", ""); while (resultSet.next()) { System.out.println(resultSet.getString("TABLE_SCHEM ") + " - " + resultSet.getString("COLUMN_NAME ")); }/* w w w .jav a2 s .c o m*/ }
From source file:Main.java
public static void main(String[] argv) throws Exception { String driver = "com.mysql.jdbc.Driver"; String user = "root"; String pass = "root"; Class.forName(driver);/*from w ww . j a va 2 s .co m*/ Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/jdbctutorial", user, pass); DatabaseMetaData dbm = con.getMetaData(); String[] types = { "TABLE" }; ResultSet rs = dbm.getTables(null, null, "%", types); System.out.println("Table name:"); while (rs.next()) { String table = rs.getString("TABLE_NAME"); System.out.println(table); con.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 a v a 2 s .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(); ResultSet resultSet = dbmd.getTypeInfo(); while (resultSet.next()) { String typeName = resultSet.getString("TYPE_NAME"); short dataType = resultSet.getShort("DATA_TYPE"); getJdbcTypeName(dataType); } }
From source file:TXInfo.java
public static void main(String[] a) throws Exception { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con = DriverManager.getConnection("jdbc:odbc:MusicVideo"); int tx = con.getMetaData().getDefaultTransactionIsolation(); String txtxt = null;//from ww w . j a v a 2s . c om switch (tx) { case Connection.TRANSACTION_NONE: txtxt = "TRANSACTION_NONE"; break; case Connection.TRANSACTION_READ_COMMITTED: txtxt = "TRANSACTION_READ_COMMITTED"; break; case Connection.TRANSACTION_READ_UNCOMMITTED: txtxt = "TRANSACTION_READ_UNCOMMITTED"; break; case Connection.TRANSACTION_REPEATABLE_READ: txtxt = "TRANSACTION_REPEATABLE_READ"; break; case Connection.TRANSACTION_SERIALIZABLE: txtxt = "TRANSACTION_SERIALIZABLE"; break; default: txtxt = "UNKNOWN!!"; } System.out.println(txtxt); con.setTransactionIsolation(tx); System.out.println("Done"); con.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ); System.out.println("TX is now " + con.getTransactionIsolation()); }
From source file:Main.java
public static void main(String[] argv) throws Exception { String driverName = "com.jnetdirect.jsql.JSQLDriver"; Class.forName(driverName);/*from w w w . j a v a 2 s .c o 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(); ResultSet resultSet = dbmd.getTypeInfo(); while (resultSet.next()) { // Get the database-specific type name String typeName = resultSet.getString("TYPE_NAME"); // Get the java.sql.Types type to which this database-specific type is // mapped short dataType = resultSet.getShort("DATA_TYPE"); getJdbcTypeName(dataType); } }
From source file:ListTables.java
public static void main(String[] args) throws Exception { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); // Enable logging // DriverManager.setLogStream(System.err); System.out.println("Getting Connection"); Connection c = DriverManager.getConnection("jdbc:odbc:Companies", "ian", ""); // user, passwd DatabaseMetaData md = c.getMetaData(); ResultSet rs = md.getTables(null, null, "%", null); while (rs.next()) { System.out.println(rs.getString(3)); }// w ww. j a v a2 s .c o m }