package javatemplate1; //pgsVisitor1B for testing codes import java.sql.*; import java.sql.ResultSet; // for result set import java.sql.Statement; import java.util.logging.Level; import java.util.logging.Logger; import javax.sql.rowset.CachedRowSet; import com.sun.rowset.CachedRowSetImpl; public class JavaTemplate1 { // example of public static void main(String[] args) throws InterruptedException { // TODO code application logic here System.out.println("main block executing "); Connection c = null; //manage copnnection PreparedStatement pst = null;// query statement support ResultSet rs = null;// active connection database result String dbURL = "jdbc:postgresql://localhost:5432/pgsdemo1"; String user = "postgres"; String pwd = "postgre_manas9"; //String dbURL = "jdbc:mysql://localhost/test?"; //String user = "Manas9"; String pwd = "Manas9237"; String sqlQuery = "SELECT id, fname ,lname,age FROM pgsVisitor1B WHERE Id=102;" + "SELECT id, fname ,lname,age FROM pgsVisitor1B WHERE Id=103;" + "SELECT id, fname ,lname,age FROM pgsVisitor1B WHERE Id=104;"; // connecting to db try { // connection>>statement >> Resultset c = DriverManager.getConnection(dbURL,user,pwd); pst = c.prepareStatement(sqlQuery); boolean isResult= pst.execute(); // do { rs = pst.getResultSet(); while (rs.next()) { System.out.print( rs.getInt(1)+ " "+ rs.getString(2)+ " " +rs.getString(3)+ " " +rs.getInt(4)); System.out.println(); } isResult = pst.getMoreResults(); } while (isResult); } catch (SQLException ex) { ex.getErrorCode(); String message = ex.getMessage(); System.out.println(message); } finally { System.out.println("going through final block"); try { if (pst== null || pst.isClosed()) { } else { pst.close(); } if (c != null && !c.isClosed()) { c.close(); } } catch (SQLException ex) { ex.getErrorCode(); ex.getMessage(); } } System.out.println("dis-Connected to database successfully"); } }