public boolean updateUser(User user) { // TODO Auto-generated method stub String sql = "update Customer set password='******',passwordsalt='" + user.getPasswordSalt() + "',email='" + user.getEmail() + "' where username='******'"; String url = "jdbc:oracle:thin:@oracle.cise.ufl.edu:1521:orcl"; System.out.println(sql); 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(sql); stmt.close(); con.close(); return true; } catch (SQLException ex) { System.out.println(ex.getMessage()); } return false; }
public boolean insertUser(User user) { // TODO Auto-generated method stub String url = "jdbc:oracle:thin:@oracle.cise.ufl.edu:1521:orcl"; String sql1 = "select max(ID) from Customer"; String sql2 = "insert into Customer values(?,?,?,?,?,?,?,?)"; String sql3 = "insert into CustomerAddr values(?,?)"; String sql4 = "select max(ID) from Address"; System.out.println(sql2); 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(); ResultSet rs = stmt.executeQuery(sql1); int ID = 0; int ID2 = 0; while (rs.next()) { ID = rs.getInt(1) + 1; System.out.println(ID); } ResultSet rs2 = stmt.executeQuery(sql4); while (rs2.next()) { ID2 = rs2.getInt(1); System.out.println(ID2); } PreparedStatement ps = con.prepareStatement(sql2); ps.setInt(1, ID); ps.setTimestamp(2, user.getCreateTime()); ps.setString(3, user.getPasswordSalt()); ps.setString(4, user.getPassword()); ps.setString(5, user.getEmail()); ps.setString(6, user.getUsername()); ps.setInt(7, ID2); ps.setInt(8, ID2); ps.executeUpdate(); ps = con.prepareStatement(sql3); System.out.println(sql3); ps.setInt(1, ID); ps.setInt(2, ID2); ps.executeUpdate(); stmt.close(); con.close(); return true; } catch (SQLException ex) { System.out.println(ex.getMessage()); } return false; }