import java.sql.*; import java.util.*; public class ConnectU { Connection con; ResourceBundle rbConnect; ResultSet rs; ResultSetMetaData rsmd; Statement stmt; String sDriver, sDriverKey = "CSDriver", sPassword, sPasswordKey ="CSPassword", sQuery = "SELECT * FROM JJJJData " + "WHERE Type = 'MoJava'", srbName = "ConnectU", sURL, sURLKey="CSURL", sUserID, sUserIDKey = "CSUserID"; public ConnectU() { try // get the PropertyResourceBundle { rbConnect = ResourceBundle.getBundle( srbName ); sDriver = rbConnect.getString( sDriverKey ); sPassword = rbConnect.getString( sPasswordKey ); sURL = rbConnect.getString( sURLKey ); sUserID = rbConnect.getString( sUserIDKey ); } catch( MissingResourceException mre ) { System.err.println( "ResourceBundle problem for " + srbName + ", program ends." ); System.err.println("Specific error: " + mre.getMessage() ); return; // exit on error } try // Attempt to load the JDBC driver { // with newInstance Class.forName( sDriver ).newInstance(); } catch( Exception e ) // error { System.err.println( "Failed to load current driver."); return; } // end catch try { con = DriverManager.getConnection ( sURL, sUserID, sPassword); DatabaseMetaData dbmd = con.getMetaData(); System.out.println( "DBMS: " + dbmd.getDatabaseProductName() + ", " + dbmd.getDatabaseProductVersion() ); System.out.println( "Driver: " + dbmd.getDriverName() + ", " + dbmd.getDriverVersion() ); stmt = con.createStatement(); } catch ( SQLException SQLe) { System.err.println( "problems connecting to " + sURL + ":" ); System.err.println( SQLe.getMessage() ); System.err.println( "SQL State: " + SQLe.getSQLState() ); if( con != null) { try { con.close(); } catch( Exception e ) {} } return; } // end catch try { rs = stmt.executeQuery( sQuery ); if( rs.next() ) // get first row { // if data was returned rsmd = rs.getMetaData(); System.out.println(); int i = rsmd.getColumnCount(); for( int ndx = 1; ndx <= i; ndx++ ) { System.out.println( "Column Name: " + rsmd.getColumnName( ndx ) + "." ); System.out.println( "Column SQL Type: " + rsmd.getColumnTypeName( ndx ) + "." ); System.out.println( "Column Java Class Equivalent: " + rsmd.getColumnClassName( ndx ) + ".\n" ); } } // end if( result.next() ) } // end try catch (Exception e) { e.printStackTrace(); } finally { try { stmt.close(); } catch( Exception e ) {} try { con.close(); } catch( Exception e ) {} } // end finally clause } // end constructor public static void main (String args[]) { new ConnectU(); } // end main } // end class ConnectU