import java.sql.*; public class Bankjdbc03 { double balance; // I don't think I need a main anymore. // public static void main(String args[]) { } public double getBalance(String username,String password){ Connection con; String query="select balance from hometown where username=\"" + username + "\" " + "and password=\"" + password +"\""; Statement stmt; try { Class.forName("org.gjt.mm.mysql.Driver"); } catch(java.lang.ClassNotFoundException e) { System.err.print("ClassNotFoundException: "); System.err.println(e.getMessage()); } try { con = DriverManager.getConnection("jdbc:mysql:///bank","",""); stmt=con.createStatement(); ResultSet rs = stmt.executeQuery(query); balance=-1.0; if (rs.next()){ balance = rs.getDouble("balance"); } stmt.close(); con.close(); } catch(SQLException ex) { System.err.print("SQLException: "); System.err.println(ex.getMessage()); } return balance; }// end getBalance member public double setBalance(String username,String password,double balance){ Connection con; String updateString="update hometown set balance=" + balance +" where " + " username=\"" + username + "\" and " + " password=\"" + password +"\" "; Statement stmt=null; try { Class.forName("org.gjt.mm.mysql.Driver"); } catch(java.lang.ClassNotFoundException e) { System.err.print("ClassNotFoundException: "); System.err.println(e.getMessage()); } try { con = DriverManager.getConnection("jdbc:mysql:///bank","",""); System.out.println("just after getConnection"); stmt = con.createStatement(); stmt.executeUpdate(updateString); stmt.close(); con.close(); } catch(SQLException ex) { System.err.print("SQLException: "); System.err.println(ex.getMessage()); } return balance; }// end setBalance member }// end class