-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDBConnection.java
More file actions
47 lines (40 loc) · 1.49 KB
/
Copy pathDBConnection.java
File metadata and controls
47 lines (40 loc) · 1.49 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
package DBConnection;
import Model.Mystore;
import com.mysql.cj.protocol.Resultset;
import java.sql.*;
public class DBConnection {
// private String url = "jdbc:mysql://localhost:3306/mystore";
// private String dbuName = "root";
// private String dbPassword = "";
// private String dbDriver = "com.mysql.jdbc.Driver";
private static Connection connect() {
//Connection con = null;
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/mystore", "root", "");
System.out.println("Connected Database");
} catch (SQLException e) {
e.printStackTrace();
return null;
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
public static Resultset loginuser(Mystore mystore, String sql) {
// ResultSet rs = null;
//Connection con = connect();
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/mystore", "root", "");
PreparedStatement pst = con.prepareStatement("select * from users where name=? and password=?");
pst.setString(1, mystore.getName());
pst.setString(2, mystore.getPassword());
ResultSet rs =pst.executeQuery();
} catch (SQLException e){
e.printStackTrace();
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
return null;
}
}