-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSqlConnection.java
39 lines (36 loc) · 1.17 KB
/
SqlConnection.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
35
36
37
38
39
package com.roy.abhisek;
import java.sql.*;
import org.eclipse.jdt.internal.compiler.ast.ReturnStatement;
public class SqlConnection {
String url="jdbc:mysql://localhost:3306/abhisek";
String username="root";
String password ="abhisek@247767";
String query="select * from login where uname=? and upass=?";
public boolean check (String name ,String pass) {
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection(url,username,password).create;
// PreparedStatement st =con.prepareStatement(query);
// st.setString(1, name);
// st.setString(2, pass);
// st.executeUpdate();
// System.out.println("Data inserted successfully!!");
// st.close();
// con.close();
Statement statement = con.createStatement();
ResultSet rs = statement.executeQuery(query);
statement.close();
con.close();
while(rs.next()) {
if(rs.getString("name").equals(name) && rs.getString("pass").equals(pass)) {
System.out.println("you are already registered");
}
}
// System.out.println(+"\n"+rs.getString("pass"));
}
catch(Exception e){
e.printStackTrace();
}
return false;
}
}