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 { ResultSet resultSet = null;//from ww w .jav a 2s . c o m Class.forName(DRIVER); Connection connection = DriverManager.getConnection(URL, USERNAME, PASSWORD); DatabaseMetaData metadata = connection.getMetaData(); resultSet = metadata.getTypeInfo(); while (resultSet.next()) { String typeName = resultSet.getString("TYPE_NAME"); System.out.println("Type Name = " + typeName); } resultSet.close(); connection.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { try {//from w w w . j a va 2 s . c o m String url = "jdbc:odbc:yourdatabasename"; String driver = "sun.jdbc.odbc.JdbcOdbcDriver"; String user = "guest"; String password = "guest"; Class.forName(driver); Connection connection = DriverManager.getConnection(url, user, password); DatabaseMetaData meta = connection.getMetaData(); System.out.println("We are using " + meta.getDatabaseProductName()); System.out.println("Version is " + meta.getDatabaseProductVersion()); connection.close(); } catch (Exception e) { System.err.println(e); } }
From source file:Main.java
public static void main(String[] args) throws Exception { Class.forName(DRIVER);/*from ww w . jav a2s . c o m*/ Connection connection = DriverManager.getConnection(URL, USERNAME, PASSWORD); DatabaseMetaData metadata = connection.getMetaData(); boolean supportForwardOnly = metadata.supportsResultSetType(ResultSet.TYPE_FORWARD_ONLY); System.out.println("supportForwardOnly = " + supportForwardOnly); boolean supportScrollInsensitive = metadata.supportsResultSetType(ResultSet.TYPE_SCROLL_INSENSITIVE); System.out.println("supportScrollInsensitive = " + supportScrollInsensitive); boolean supportScrollSensitive = metadata.supportsResultSetType(ResultSet.TYPE_SCROLL_SENSITIVE); System.out.println("supportScrollSensitive = " + supportScrollSensitive); connection.close(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { String driverName = "com.jnetdirect.jsql.JSQLDriver"; Class.forName(driverName);/* w w w. ja va 2s.com*/ 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"); } }
From source file:Main.java
public static void main(String[] args) throws Exception { Class.forName(DRIVER);//from w w w . ja va 2 s . co m Connection connection = DriverManager.getConnection(URL, USERNAME, PASSWORD); DatabaseMetaData metadata = connection.getMetaData(); ResultSet resultSet = metadata.getColumns(null, null, "users", null); while (resultSet.next()) { String name = resultSet.getString("COLUMN_NAME"); String type = resultSet.getString("TYPE_NAME"); int size = resultSet.getInt("COLUMN_SIZE"); System.out.println("Column name: [" + name + "]; type: [" + type + "]; size: [" + size + "]"); } 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 .j a va 2s . 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 dmd = connection.getMetaData(); if (dmd.supportsTransactions()) { // Transactions are supported } else { // Transactions are not supported } }
From source file:Main.java
public static void main(String[] argv) throws Exception { String driverName = "com.jnetdirect.jsql.JSQLDriver"; Class.forName(driverName);/* w w w. j a v a2 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()) { // Get the database-specific type name String typeName = resultSet.getString("TYPE_NAME"); short dataType = resultSet.getShort("DATA_TYPE"); } }
From source file:Main.java
public static void main(String[] args) throws Exception { Class.forName(DRIVER);/* w ww . j a va2 s . c o m*/ Connection connection = DriverManager.getConnection(URL, USERNAME, PASSWORD); DatabaseMetaData metadata = connection.getMetaData(); String driverName = metadata.getDriverName(); String driverVersion = metadata.getDriverVersion(); int majorVersion = metadata.getDriverMajorVersion(); int minorVersion = metadata.getDriverMinorVersion(); System.out.println("driverName = " + driverName); System.out.println("driverVersion = " + driverVersion); System.out.println("majorVersion = " + majorVersion); System.out.println("minorVersion = " + minorVersion); 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 w w . ja va 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()) { // 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"); } }
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 va2 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 dmd = connection.getMetaData(); if (dmd.supportsResultSetType(ResultSet.TYPE_SCROLL_INSENSITIVE)) { System.out.println("Insensitive scrollable result sets are supported"); } if (dmd.supportsResultSetType(ResultSet.TYPE_SCROLL_SENSITIVE)) { System.out.println("Sensitive scrollable result sets are supported"); } if (!dmd.supportsResultSetType(ResultSet.TYPE_SCROLL_INSENSITIVE) && !dmd.supportsResultSetType(ResultSet.TYPE_SCROLL_SENSITIVE)) { System.out.println("Updatable result sets are not supported"); } }