List of usage examples for java.sql DatabaseMetaData getDriverVersion
String getDriverVersion() throws SQLException;
String
. From source file:Main.java
public static void main(String[] args) throws Exception { Connection conn = getHSQLConnection(); DatabaseMetaData md = conn.getMetaData(); System.out.println(md.getDriverVersion()); conn.close();//from w w w. j a v a 2s . co m }
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 a v a2s . co m*/ }
From source file:Main.java
public static void main(String[] args) throws Exception { Connection conn = getMySqlConnection(); System.out.println("Got Connection."); Statement st = conn.createStatement(); st.executeUpdate("drop table survey;"); st.executeUpdate("create table survey (id int,name varchar(30));"); st.executeUpdate("insert into survey (id,name ) values (1,'nameValue')"); ResultSet rs = null;/*w w w . j a v a2 s . c o m*/ DatabaseMetaData meta = conn.getMetaData(); System.out.println(meta.getDriverVersion()); st.close(); conn.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { Connection conn = getHSQLConnection(); DatabaseMetaData md = conn.getMetaData(); System.out.println("JDBC Driver: " + md.getDriverName() + " " + md.getDriverVersion()); System.out.println("Database: " + md.getURL()); System.out.println("User: " + md.getUserName()); conn.close();// w w w . jav a 2 s .com }
From source file:Main.java
public static void main(String[] args) throws Exception { Class.forName(DRIVER);//from ww w. j a v a 2s. co 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[] args) throws Exception { String url = "jdbc:odbc:databaseName"; String driver = "sun.jdbc.odbc.JdbcOdbcDriver"; String user = "guest"; String password = "guest"; try {//w w w . java 2 s . c o m Class.forName(driver); Connection conn = DriverManager.getConnection(url, user, password); // Get the MetaData DatabaseMetaData metaData = conn.getMetaData(); // Get driver information System.out.println("Driver Informaion"); System.out.println(metaData.getDriverName()); System.out.println(metaData.getDriverVersion()); // Get schema information System.out.println("Schemas"); ResultSet schemas = metaData.getSchemas(); while (schemas.next()) { System.out.println(schemas.getString(1)); } // Get table information System.out.println("Tables"); ResultSet tables = metaData.getTables("", "", "", null); while (tables.next()) { System.out.println(tables.getString(3)); } conn.close(); } catch (Exception ex) { ex.printStackTrace(); } }
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();/*from ww w .j a v a 2s . c o m*/ }
From source file:GetDBInfo.java
public static void main(String[] args) { Connection c = null; // The JDBC connection to the database server try {/*from w w w . j a va 2 s . co 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[] args) throws Exception { Connection conn = getMySqlConnection(); System.out.println("Got Connection."); Statement st = conn.createStatement(); st.executeUpdate("drop table survey;"); st.executeUpdate("create table survey (id int,name varchar(30));"); st.executeUpdate("insert into survey (id,name ) values (1,'nameValue')"); 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 ww w.j a v a 2 s . co m*/ int jdbcMajorVersion = meta.getJDBCMajorVersion(); System.out.println("jdbcMajorVersion:" + jdbcMajorVersion); } catch (Exception e) { System.out.println("jdbcMajorVersion unsupported feature"); } try { int jdbcMinorVersion = meta.getJDBCMinorVersion(); System.out.println("jdbcMinorVersion:" + jdbcMinorVersion); } catch (Exception e) { System.out.println("jdbcMinorVersion unsupported feature"); } String driverName = meta.getDriverName(); String driverVersion = meta.getDriverVersion(); System.out.println("driverName=" + driverName); System.out.println("driverVersion=" + driverVersion); st.close(); conn.close(); }
From source file:com.aurel.track.admin.server.status.ServerStatusBL.java
private static void loadDatabaseInfo(ServerStatusTO serverStatusTO) { Connection conn = null;//from w w w.j a va2 s . c o m try { conn = Torque.getConnection(BaseTSitePeer.DATABASE_NAME); DatabaseMetaData dbm = conn.getMetaData(); serverStatusTO.setDatabase(dbm.getDatabaseProductName() + " " + dbm.getDatabaseProductVersion()); serverStatusTO.setJdbcDriver(dbm.getDriverName() + " " + dbm.getDriverVersion()); serverStatusTO.setJdbcUrl(dbm.getURL()); } catch (Exception e) { LOGGER.error("Problem retrieving database meta data: " + e.getMessage()); } finally { if (conn != null) { Torque.closeConnection(conn); } } Double ping = loadPing(); serverStatusTO.setPingTime(ping.toString() + " ms"); }