List of usage examples for java.sql DatabaseMetaData getDatabaseProductVersion
String getDatabaseProductVersion() throws SQLException;
From source file:Main.java
public static void main(String[] args) throws Exception { Connection conn = getHSQLConnection(); DatabaseMetaData meta = conn.getMetaData(); String productName = meta.getDatabaseProductName(); String productVersion = meta.getDatabaseProductVersion(); System.out.println("productName:" + productName); System.out.println("productVersion:" + productVersion); conn.close();/* ww w. j av a 2s. com*/ }
From source file:Main.java
public static void main(String[] args) throws Exception { try {/*from w ww . j av a 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:JDBCMeta.java
public static void main(String[] av) { int i;//from w ww . j av a2s .c om try { // Load the driver Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); // Enable logging // DriverManager.setLogStream(System.err); System.out.println("Getting Connection"); Connection conn = DriverManager.getConnection("jdbc:odbc:Companies", "ian", ""); // user, passwd // Get a Database MetaData as a way of interrogating // the names of the tables in this database. DatabaseMetaData meta = conn.getMetaData(); System.out.println("We are using " + meta.getDatabaseProductName()); System.out.println("Version is " + meta.getDatabaseProductVersion()); int txisolation = meta.getDefaultTransactionIsolation(); System.out.println("Database default transaction isolation is " + txisolation + " (" + transactionIsolationToString(txisolation) + ")."); conn.close(); System.out.println("All done!"); } catch (ClassNotFoundException e) { System.out.println("Can't load driver " + e); } catch (SQLException ex) { System.out.println("Database access failed:"); System.out.println(ex); } }
From source file:Main.java
public static void main(String[] args) throws Exception { Connection conn = getConnection(); DatabaseMetaData mtdt = conn.getMetaData(); System.out.println("URL in use: " + mtdt.getURL()); System.out.println("User name: " + mtdt.getUserName()); System.out.println("DBMS name: " + mtdt.getDatabaseProductName()); System.out.println("DBMS version: " + mtdt.getDatabaseProductVersion()); System.out.println("Driver name: " + mtdt.getDriverName()); System.out.println("Driver version: " + mtdt.getDriverVersion()); System.out.println("supp. SQL Keywords: " + mtdt.getSQLKeywords()); conn.close();/* w ww . j a va 2 s. c om*/ }
From source file:info.extensiblecatalog.OAIToolkit.db.DButil.java
public static void main(String[] args) throws ClassNotFoundException, SQLException, Exception { DButil.load("db.properties"); DatabaseMetaData meta = DButil.getMetadata(); prglog.info("[PRG] " + meta.getDatabaseProductName() + " " + meta.getDatabaseProductVersion() /*//from www. j a va 2 s . c o m + " " + meta.getDriverMajorVersion() + "." + meta.getDriverMinorVersion() + " " + meta.getDatabaseMajorVersion() + "." + meta.getDatabaseMinorVersion() */ ); }
From source file:Main.java
public static void main(String[] args) { long begTime = System.currentTimeMillis(); String driver = DEFAULT_DRIVER; String url = DEFAULT_URL; String username = DEFAULT_USERNAME; String password = DEFAULT_PASSWORD; Connection connection = null; try {/*from w w w. j a v a 2 s . co m*/ connection = createConnection(driver, url, username, password); DatabaseMetaData meta = connection.getMetaData(); System.out.println(meta.getDatabaseProductName()); System.out.println(meta.getDatabaseProductVersion()); String sqlQuery = "SELECT PERSON_ID, FIRST_NAME, LAST_NAME FROM PERSON"; System.out.println("before insert: " + query(connection, sqlQuery, Collections.EMPTY_LIST)); connection.setAutoCommit(false); String sqlUpdate = "INSERT INTO PERSON(FIRST_NAME, LAST_NAME) VALUES(?,?)"; List parameters = Arrays.asList("Foo", "Bar"); int numRowsUpdated = update(connection, sqlUpdate, parameters); connection.commit(); System.out.println("# rows inserted: " + numRowsUpdated); System.out.println("after insert: " + query(connection, sqlQuery, Collections.EMPTY_LIST)); } catch (Exception e) { rollback(connection); e.printStackTrace(); } finally { close(connection); long endTime = System.currentTimeMillis(); System.out.println("wall time: " + (endTime - begTime) + " ms"); } }
From source file:GetDBInfo.java
public static void main(String[] args) { Connection c = null; // The JDBC connection to the database server try {//from w ww . j a va 2s . c o m // Look for the properties file DB.props in the same directory as // this program. It will contain default values for the various // parameters needed to connect to a database Properties p = new Properties(); try { p.load(GetDBInfo.class.getResourceAsStream("DB.props")); } catch (Exception e) { } // Get default values from the properties file String driver = p.getProperty("driver"); // Driver class name String server = p.getProperty("server", ""); // JDBC URL for server String user = p.getProperty("user", ""); // db user name String password = p.getProperty("password", ""); // db password // These variables don't have defaults String database = null; // The db name (appended to server URL) String table = null; // The optional name of a table in the db // Parse the command-line args to override the default values above for (int i = 0; i < args.length; i++) { if (args[i].equals("-d")) driver = args[++i]; //-d <driver> else if (args[i].equals("-s")) server = args[++i];//-s <server> else if (args[i].equals("-u")) user = args[++i]; //-u <user> else if (args[i].equals("-p")) password = args[++i]; else if (database == null) database = args[i]; // <dbname> else if (table == null) table = args[i]; // <table> else throw new IllegalArgumentException("Unknown argument: " + args[i]); } // Make sure that at least a server or a database were specified. // If not, we have no idea what to connect to, and cannot continue. if ((server.length() == 0) && (database.length() == 0)) throw new IllegalArgumentException("No database specified."); // Load the db driver, if any was specified. if (driver != null) Class.forName(driver); // Now attempt to open a connection to the specified database on // the specified server, using the specified name and password c = DriverManager.getConnection(server + database, user, password); // Get the DatabaseMetaData object for the connection. This is the // object that will return us all the data we're interested in here DatabaseMetaData md = c.getMetaData(); // Display information about the server, the driver, etc. System.out.println("DBMS: " + md.getDatabaseProductName() + " " + md.getDatabaseProductVersion()); System.out.println("JDBC Driver: " + md.getDriverName() + " " + md.getDriverVersion()); System.out.println("Database: " + md.getURL()); System.out.println("User: " + md.getUserName()); // Now, if the user did not specify a table, then display a list of // all tables defined in the named database. Note that tables are // returned in a ResultSet, just like query results are. if (table == null) { System.out.println("Tables:"); ResultSet r = md.getTables("", "", "%", null); while (r.next()) System.out.println("\t" + r.getString(3)); } // Otherwise, list all columns of the specified table. // Again, information about the columns is returned in a ResultSet else { System.out.println("Columns of " + table + ": "); ResultSet r = md.getColumns("", "", table, "%"); while (r.next()) System.out.println("\t" + r.getString(4) + " : " + r.getString(6)); } } // Print an error message if anything goes wrong. catch (Exception e) { System.err.println(e); if (e instanceof SQLException) System.err.println(((SQLException) e).getSQLState()); System.err.println("Usage: java GetDBInfo [-d <driver] " + "[-s <dbserver>]\n" + "\t[-u <username>] [-p <password>] <dbname>"); } // Always remember to close the Connection object when we're done! finally { try { c.close(); } catch (Exception e) { } } }
From source file:Main.java
public static void main(String[] argv) { Connection connection = null; Statement statement;//from w ww.j av a 2 s.c om ResultSet rs; try { Context ctx = new InitialContext(); DataSource ds = (DataSource) ctx.lookup("java:comp/env/jdbc/AccountsDB"); connection = ds.getConnection(); DatabaseMetaData md = connection.getMetaData(); statement = connection.createStatement(); System.out.println("getURL() - " + md.getURL()); System.out.println("getUserName() - " + md.getUserName()); System.out.println("getDatabaseProductVersion - " + md.getDatabaseProductVersion()); System.out.println("getDriverMajorVersion - " + md.getDriverMajorVersion()); System.out.println("getDriverMinorVersion - " + md.getDriverMinorVersion()); System.out.println("nullAreSortedHigh - " + md.nullsAreSortedHigh()); System.out.println("<H1>Feature Support</H1>"); System.out.println( "supportsAlterTableWithDropColumn - " + md.supportsAlterTableWithDropColumn() + "<BR>"); System.out.println("supportsBatchUpdates - " + md.supportsBatchUpdates()); System.out.println("supportsTableCorrelationNames - " + md.supportsTableCorrelationNames()); System.out.println("supportsPositionedDelete - " + md.supportsPositionedDelete()); System.out.println("supportsFullOuterJoins - " + md.supportsFullOuterJoins()); System.out.println("supportsStoredProcedures - " + md.supportsStoredProcedures()); System.out.println("supportsMixedCaseQuotedIdentifiers - " + md.supportsMixedCaseQuotedIdentifiers()); System.out.println("supportsANSI92EntryLevelSQL - " + md.supportsANSI92EntryLevelSQL()); System.out.println("supportsCoreSQLGrammar - " + md.supportsCoreSQLGrammar()); System.out.println("getMaxRowSize - " + md.getMaxRowSize()); System.out.println("getMaxStatementLength - " + md.getMaxStatementLength()); System.out.println("getMaxTablesInSelect - " + md.getMaxTablesInSelect()); System.out.println("getMaxConnections - " + md.getMaxConnections()); System.out.println("getMaxCharLiteralLength - " + md.getMaxCharLiteralLength()); System.out.println("getTableTypes()"); rs = md.getTableTypes(); while (rs.next()) { System.out.println(rs.getString(1)); } System.out.println("getTables()"); rs = md.getTables("accounts", "", "%", new String[0]); while (rs.next()) { System.out.println(rs.getString("TABLE_NAME")); } System.out.println("Transaction Support"); System.out.println("getDefaultTransactionIsolation() - " + md.getDefaultTransactionIsolation()); System.out .println("dataDefinitionIgnoredInTransactions() - " + md.dataDefinitionIgnoredInTransactions()); System.out.println("General Source Information"); System.out.println("getMaxTablesInSelect - " + md.getMaxTablesInSelect()); System.out.println("getMaxColumnsInTable - " + md.getMaxColumnsInTable()); System.out.println("getTimeDateFunctions - " + md.getTimeDateFunctions()); System.out.println("supportsCoreSQLGrammar - " + md.supportsCoreSQLGrammar()); System.out.println("getTypeInfo()"); rs = md.getTypeInfo(); while (rs.next()) { System.out.println(rs.getString(1)); } } catch (Exception e) { e.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) throws Exception { Class.forName(DRIVER);/*from ww w. j av a2s . co 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[] args) throws Exception { Connection conn = getMySqlConnection(); DatabaseMetaData meta = conn.getMetaData(); try {//from ww w. j av a 2s.co m 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(); }