-
Notifications
You must be signed in to change notification settings - Fork 0
/
ValidateUnameServlet.java
51 lines (40 loc) · 1.5 KB
/
ValidateUnameServlet.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
40
41
42
43
44
45
46
47
48
49
50
51
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
public class ValidateUnameServlet extends HttpServlet {
// JDBC driver name and database URL
static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
static final String DB_URL="jdbc:mysql://localhost:3306/TIMS";
// Database credentials
static final String USER = "root";
static final String PASS = "Subhi@123";
public void doGet(HttpServletRequest request, HttpServletResponse response){
try{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
//out.println("<p>Driver Access Initialising....</p>");
Class.forName(JDBC_DRIVER);
//out.println("<p>Driver Access Succesful....</p>");
Connection conn = DriverManager.getConnection(DB_URL, USER, PASS);
//out.println("<p>Database Connection Successful....</p>");
String uid = request.getParameter("uid");
// Execute SQL query
Statement stmt = conn.createStatement();
String sql = "SELECT * FROM users WHERE uid='"+uid+"'";
ResultSet rs = stmt.executeQuery(sql);
if(rs.next()){
//out.println(uname + ",, " +pwd);
out.println("0");
}
else{
out.println("1");
}
conn.close();
}
catch(Exception e){
System.out.println(e);
}
}
}