import java.util.*; import java.sql.*; class test { public static void printSQLException(SQLException e) { e.printStackTrace(); while(e != null) { System.out.println(e); e = e.getNextException(); } } public static Connection openDatabase(String strDriver, String strURL, String strUserId, String strUserPswd) { Connection conn; try { // Load the jdbc driver. Class drvClass = Class.forName(strDriver); DriverManager.registerDriver( (Driver) drvClass.newInstance()); DriverManager.setLoginTimeout(900); //15 minute timeout // Attempt to connect to a driver. conn = DriverManager.getConnection(strURL, strUserId, strUserPswd); } catch (SQLException e) { printSQLException(e); return null; } catch (ClassNotFoundException e) { e.printStackTrace(); // for debugging return null; } catch (InstantiationException e) { e.printStackTrace(); return null; } catch (IllegalAccessException e) { e.printStackTrace(); return null; } return conn; } public static boolean closeDatabase(Connection conn) { if(conn == null) return true; try { conn.close(); } catch (SQLException e) { return false; } return true; } public static void access(Connection db, int msg_id, int no_msgs) { Statement get_stmt; ResultSet get_rs; Statement update_stmt; ResultSet update_rs; int[] inst_id_ar = new int[50]; int[] obj_type_ar = new int[50]; int counter try { get_stmt = db.createStatement(); update_stmt = db.createStatement(); get_rs = get_stmt.executeQuery("SELECT * from test_table "); while(get_rs.next()) { System.out.println(dummy_rs.getInt("Instr_ID")); System.out.println(dummy_rs.getString("Obj_Type")); } // while end update_stmt.executeUpdate("insert into test_table values ( 'Success', 1 )"); } // end try catch(SQLException e) { printSQLException(e); return; } } public static void main(String args[]) throws Exception { Connection db = openDatabase("com.sybase.jdbc3.jdbc.SybDriver", "jdbc:sybase:Tds:localhost:2638?ServiceName=storage", "Test", "Dummy"); access(db); closeDatabase(db); } }