daily pastebin goal
6%
SHARE
TWEET

Untitled

a guest Sep 24th, 2016 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.sql.Connection;
  2.     import java.sql.PreparedStatement;
  3.     import java.sql.ResultSet;
  4.     import java.sql.SQLException;
  5.    
  6. String sql = "Select a.User_Name, a.Password, a.Gender from user_account a "
  7.           + " where a.User_Name = ? and a.password= ?";
  8.  
  9.   PreparedStatement pstm = conn.prepareStatement(sql);
  10.   pstm.setString(1, userName);
  11.   pstm.setString(2, password);
  12.   ResultSet rs = pstm.executeQuery();
  13.  
  14.   if (rs.next()) {
  15.       String gender = rs.getString("Gender");
  16.       UserAccount user = new UserAccount();
  17.       user.setUserName(userName);
  18.       user.setPassword(password);
  19.       user.setGender(gender);
  20.       return user;
  21.   }
  22.   return null;
  23.    
  24. String sql = "Select a.User_Name, a.Password, a.Gender from user_account a " + " where a.User_Name = ? ";
  25.  
  26.   PreparedStatement pstm = conn.prepareStatement(sql);
  27.   pstm.setString(1, userName);
  28.  
  29.   ResultSet rs = pstm.executeQuery();
  30.  
  31.   if (rs.next()) {
  32.       String password = rs.getString("Password");
  33.       String gender = rs.getString("Gender");
  34.       UserAccount user = new UserAccount();
  35.       user.setUserName(userName);
  36.       user.setPassword(password);
  37.       user.setGender(gender);
  38.       return user;
  39.   }
  40.   return null;
  41.    
  42. PreparedStatement pstm = conn.prepareStatement(sql);
  43.  
  44.   ResultSet rs = pstm.executeQuery();
  45.   List<Product> list = new ArrayList<Product>();
  46.   while (rs.next()) {
  47.       String code = rs.getString("Code");
  48.       String name = rs.getString("Name");
  49.       float price = rs.getFloat("Price");
  50.       Product product = new Product();
  51.       product.setCode(code);
  52.       product.setName(name);
  53.       product.setPrice(price);
  54.       list.add(product);
  55.   }
  56.   return list;
  57.    
  58. PreparedStatement pstm = conn.prepareStatement(sql);
  59.   pstm.setString(1, code);
  60.  
  61.   ResultSet rs = pstm.executeQuery();
  62.  
  63.   while (rs.next()) {
  64.       String name = rs.getString("Name");
  65.       float price = rs.getFloat("Price");
  66.       Product product = new Product(code, name, price);
  67.       return product;
  68.   }
  69.   return null;
  70.    
  71. PreparedStatement pstm = conn.prepareStatement(sql);
  72.  
  73.   pstm.setString(1, product.getName());
  74.   pstm.setFloat(2, product.getPrice());
  75.   pstm.setString(3, product.getCode());
  76.   pstm.executeUpdate();
  77.    
  78. PreparedStatement pstm = conn.prepareStatement(sql);
  79.  
  80.   pstm.setString(1, product.getCode());
  81.   pstm.setString(2, product.getName());
  82.   pstm.setFloat(3, product.getPrice());
  83.  
  84.   pstm.executeUpdate();
  85.    
  86. PreparedStatement pstm = conn.prepareStatement(sql);
  87.  
  88.   pstm.setString(1, code);
  89.  
  90.   pstm.executeUpdate();
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