public boolean updateAddress(Address address) { // TODO Auto-generated method stub int id = address.getId(); String url = "jdbc:oracle:thin:@oracle.cise.ufl.edu:1521:orcl"; String sql = "update Address set firstname='" + address.getFirstname() + "'," + "lastname='" + address.getLastname() + "'," + "company='" + address.getCompany() + "'," + "state='" + address.getState() + "'," + "phonenumber='" + address.getPhonenumber() + "'," + "zipcode=" + address.getZipcode() + "," + "city='" + address.getCity() + "'," + "addr_line1='" + address.getAddressline1() + "'," + "addr_line2='" + address.getAddressline2() + "' where " + "id=" + id; try { Class.forName("oracle.jdbc.driver.OracleDriver"); } catch (java.lang.ClassNotFoundException e) { System.out.println(e.getMessage()); } try { Connection con = DriverManager.getConnection(url, "dawei", "jolly900513"); Statement stmt = con.createStatement(); System.out.println(sql); stmt.executeUpdate(sql); stmt.close(); con.close(); return true; } catch (SQLException ex) { System.out.println(ex.getMessage()); } return false; }
public boolean addNewAddress(int id, Address address) { // TODO Auto-generated method stub String url = "jdbc:oracle:thin:@oracle.cise.ufl.edu:1521:orcl"; String sql1 = "select max(ID) from Address"; String sql2 = "insert into address values(?,?,?,?,?,?,?,?,?,?,?)"; String sql3 = "insert into CustomerAddr values(?,?)"; try { Class.forName("oracle.jdbc.driver.OracleDriver"); } catch (java.lang.ClassNotFoundException e) { System.out.println(e.getMessage()); } try { Connection con = DriverManager.getConnection(url, "dawei", "jolly900513"); Statement stmt = con.createStatement(); // stmt.executeUpdate(sql3); ResultSet rs = stmt.executeQuery(sql1); int ID = 0; while (rs.next()) { ID = rs.getInt(1) + 1; } PreparedStatement ps = con.prepareStatement(sql2); ps.setInt(1, ID); ps.setString(2, address.getFirstname()); ps.setString(3, address.getLastname()); ps.setString(4, address.getCompany()); ps.setString(5, address.getState()); ps.setString(6, address.getPhonenumber()); ps.setInt(7, address.getZipcode()); ps.setDate(9, (Date) address.getCreateon()); ps.setString(8, address.getCity()); ps.setString(10, address.getAddressline1()); ps.setString(11, address.getAddressline2()); System.out.println(sql2); ps.executeUpdate(); ps = con.prepareStatement(sql3); ps.setInt(1, id); ps.setInt(2, ID); System.out.println(sql3); ps.executeUpdate(); stmt.close(); con.close(); return true; } catch (SQLException ex) { System.out.println(ex.getMessage()); } return false; }