Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.Connection;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- String sql = "Select a.User_Name, a.Password, a.Gender from user_account a "
- + " where a.User_Name = ? and a.password= ?";
- PreparedStatement pstm = conn.prepareStatement(sql);
- pstm.setString(1, userName);
- pstm.setString(2, password);
- ResultSet rs = pstm.executeQuery();
- if (rs.next()) {
- String gender = rs.getString("Gender");
- UserAccount user = new UserAccount();
- user.setUserName(userName);
- user.setPassword(password);
- user.setGender(gender);
- return user;
- }
- return null;
- String sql = "Select a.User_Name, a.Password, a.Gender from user_account a " + " where a.User_Name = ? ";
- PreparedStatement pstm = conn.prepareStatement(sql);
- pstm.setString(1, userName);
- ResultSet rs = pstm.executeQuery();
- if (rs.next()) {
- String password = rs.getString("Password");
- String gender = rs.getString("Gender");
- UserAccount user = new UserAccount();
- user.setUserName(userName);
- user.setPassword(password);
- user.setGender(gender);
- return user;
- }
- return null;
- PreparedStatement pstm = conn.prepareStatement(sql);
- ResultSet rs = pstm.executeQuery();
- List<Product> list = new ArrayList<Product>();
- while (rs.next()) {
- String code = rs.getString("Code");
- String name = rs.getString("Name");
- float price = rs.getFloat("Price");
- Product product = new Product();
- product.setCode(code);
- product.setName(name);
- product.setPrice(price);
- list.add(product);
- }
- return list;
- PreparedStatement pstm = conn.prepareStatement(sql);
- pstm.setString(1, code);
- ResultSet rs = pstm.executeQuery();
- while (rs.next()) {
- String name = rs.getString("Name");
- float price = rs.getFloat("Price");
- Product product = new Product(code, name, price);
- return product;
- }
- return null;
- PreparedStatement pstm = conn.prepareStatement(sql);
- pstm.setString(1, product.getName());
- pstm.setFloat(2, product.getPrice());
- pstm.setString(3, product.getCode());
- pstm.executeUpdate();
- PreparedStatement pstm = conn.prepareStatement(sql);
- pstm.setString(1, product.getCode());
- pstm.setString(2, product.getName());
- pstm.setFloat(3, product.getPrice());
- pstm.executeUpdate();
- PreparedStatement pstm = conn.prepareStatement(sql);
- pstm.setString(1, code);
- pstm.executeUpdate();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement