Java program to determine a lost/invalid jdbc connection between 2 servers over a period of time.
import java.sql.*; import oracle.jdbc.OracleStatement; public class Test2 { public static void main(String[] args) { String url = "jdbc:oracle:thin:@<server-name>:<listener-port>:<db-service-name>"; String user = "a"; String password = "b"; try { DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver()); Connection conn = DriverManager.getConnection(url, user, password); Thread.currentThread().sleep(60 * 1000*60*2); Statement stmt = conn.createStatement(); ResultSet rset = stmt.executeQuery("select * from table"); while (rset.next()) System.out.println(rset.getString(1)); DatabaseMetaData meta = conn.getMetaData(); // gets driver info: System.out.println(" ============= Database Product Name is ... " + meta.getDatabaseProductName()); System.out.println(" Database Product Version is " + meta.getDatabaseProductVersion()); System.out.println(" ============= JDBC Driver Name is ........ " + meta.getDriverName()); System.out.println(" JDBC Driver Version is ..... " + meta.getDriverVersion()); System.out.println(" JDBC URL " + meta.getURL()); System.out.println(" ============="); //get environment info: java.util.Properties props = System.getProperties(); java.util.Enumeration propNames = props.propertyNames(); StringBuffer path = new StringBuffer(" " + props.getProperty("java.library.path")); int idx = 0; while (idx < path.length()) { idx = path.toString().indexOf(";", idx); if (idx == -1) break; path.replace(idx, ++idx, " "); idx++; } StringBuffer classpath = new StringBuffer(" " + props.getProperty("java.class.path")); int idx2 = 0; while (idx2 < classpath.length()) { idx2 = classpath.toString().indexOf(";", idx2); if (idx2 == -1) break; classpath.replace(idx2, ++idx2, " "); idx2++; } System.out.println("java runtime Version: " + props.getProperty("java.runtime.version") + " "); System.out.println("============="); System.out.println("java vm Version: " + props.getProperty("java.vm.version") + " "); System.out.println("============="); System.out.println("java vm name: " + props.getProperty("java.vm.name") + " "); System.out.println("============="); System.out.println("java library path: " + path + ""); System.out.println("============="); System.out.println("java classpath: " + classpath + ""); } catch (SQLException ex) { while (ex != null) { System.out.println("SQLState: " + ex.getSQLState()); System.out.println("Message: " + ex.getMessage()); System.out.println("Vendor: " + ex.getErrorCode()); ex.printStackTrace(); ex = ex.getNextException(); System.out.println(""); } } catch (Exception e) { e.printStackTrace(); } } //end of main }