Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package user;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- public class UserDAO {
- private Connection con;
- private PreparedStatement pstmt;
- private ResultSet rs;
- public UserDAO (){
- try {
- String dburl="jdbc:mysql://localhost:3306/shift";
- String dbId ="shift";
- String dbPassword = "shift";
- Class.forName("com.mysql.jdbc.Driver");
- con = DriverManager.getConnection(dburl, dbId, dbPassword);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- public int login (String userId, String userPassword) {
- String SQL = "SELECT userPassword FROM USER WHERE userId=? " ;
- try {
- pstmt = con.prepareStatement(SQL);
- pstmt.setString(1, userId);
- rs = pstmt.executeQuery();
- if (rs.next() ) {
- if(rs.getString(1).equals(userPassword))
- return 1;
- else return 0;
- }
- return -1;
- } catch (Exception e) {
- e.printStackTrace();
- }
- return -2;
- }
- public int join(User user){
- String SQL = "INSERT INTO USER VALUES (?, ?, ?, ?, ?)";
- try {
- pstmt = con.prepareStatement(SQL);
- pstmt.setString(1, user.getUserId());
- pstmt.setString(2, user.getUserPassword());
- pstmt.setString(3, user.getUserName());
- pstmt.setString(4, user.getUserGender());
- pstmt.setString(5, user.getUserEmail());
- return pstmt.executeUpdate();
- } catch (Exception e) {
- e.printStackTrace();
- }
- return -1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement