forked from nirala96/open_source_start
-
Notifications
You must be signed in to change notification settings - Fork 0
/
UserDAO.java
34 lines (25 loc) · 1.01 KB
/
UserDAO.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package net.codejava;
import java.sql.*;
public class UserDAO {
public User checkLogin(String email, String password) throws SQLException,
ClassNotFoundException {
String jdbcURL = "jdbc:mysql://localhost:3306/bookshop";
String dbUser = "root";
String dbPassword = "password";
Class.forName("com.mysql.jdbc.Driver");
Connection connection = DriverManager.getConnection(jdbcURL, dbUser, dbPassword);
String sql = "SELECT * FROM users WHERE email = ? and password = ?";
PreparedStatement statement = connection.prepareStatement(sql);
statement.setString(1, email);
statement.setString(2, password);
ResultSet result = statement.executeQuery();
User user = null;
if (result.next()) {
user = new User();
user.setFullname(result.getString("fullname"));
user.setEmail(email);
}
connection.close();
return user;
}
}