import java.sql.*; import java.io.*; import java.util.*; public class Browse { private final static String URL = "jdbc:mysql://192.168.1.212/webdb"; public static void main (String args []) throws SQLException, IOException { String user, pwd; Scanner scanner=null; try { Class.forName ("com.mysql.jdbc.Driver"); } catch (ClassNotFoundException e) { System.out.println ("Could not load the driver"); } scanner = new Scanner(System.in); scanner.useDelimiter(System.getProperty("line.separator")); System.out.println("Please enter database user name"); user = scanner.next(); System.out.println("Please enter database password"); pwd = scanner.next(); Connection conn = DriverManager.getConnection (URL, user, pwd); Statement stmt = conn.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY ); ResultSet rset = stmt.executeQuery ("select fname, lname, salary from employee where lname like '%s%'"); rset.last(); int nRows = rset.getRow(); System.out.println("Number of rows in the result set is " + nRows); int currentRow = 1; while (currentRow==currentRow) { rset.absolute(currentRow); int n = 0; System.out.println(""); for (int i=currentRow; i<=nRows; i++) { if (n == 5) break; System.out.println(rset.getString(1)+" "+rset.getString(2)+ " "+rset.getString(3)); rset.next(); n++; } if (currentRow == (((nRows/5)*5)+1)) { System.out.print("\n p: previous 5, q: quit"); String opt = scanner.next(); if (opt.equals("q")) return; else if (opt.equals("p")) currentRow -= 5; } else if (currentRow == 1) { System.out.print("\n n: next 5, q: quit"); String opt = scanner.next(); if (opt.equals("q")) return; else if (opt.equals("n")) currentRow += 5; } else { System.out.print("\n n: next 5, p: previous 5, q: quit"); String opt = scanner.next(); if (opt.equals("q")) return; else if (opt.equals("n")) currentRow += 5; else if (opt.equals("p")) currentRow -= 5; } } conn.close(); } }