SHARE
TWEET

Untitled

a guest Apr 27th, 2016 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public void validateLoginPreparedStatement(String username, String password) {
  2.     try {
  3.     stmt = conn.createStatement();
  4.     String query = "SELECT * FROM users where username = ? and password =?";
  5.     PreparedStatement pStat = conn.prepareStatement(query);
  6.     pStat.setString(1, username);
  7.     pStat.setString(2, password);
  8.     rs = pStat.executeQuery();
  9.     if (rs.next()) {
  10.          System.out.println("User is logged in");
  11.     } else {
  12.         System.out.println("Invalid Username and Password");}
  13.     } catch (SQLException e) {
  14.             e.printStackTrace();}}
  15.  
  16. public void insertUser() {
  17.         try {
  18.             stmt = conn.createStatement();
  19.             String insert = "INSERT INTO users (ID, username,password) values (1004, 'newUser','newPass')";
  20.             int rowCount = stmt.executeUpdate(insert);
  21.             System.out.println("row Count = " + rowCount);
  22.         } catch (SQLException e) {
  23.             e.printStackTrace();
  24.         }
  25.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top