Guest User

Untitled

a guest
Nov 23rd, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. public class DashBoard extends HttpServlet
  2. {
  3. public static final String DB_URL="jdbc:mysql://localhost/TEST";
  4. public static final String username="root";
  5. public static final String password="your-password";
  6. Connection conn=null;
  7. Statement st=null;
  8. ResultSet res=null;
  9. public void doGet(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException
  10. {
  11. PrintWriter out=response.getWriter();
  12. try
  13. {
  14. Class.forName("com.mysql.jdbc.Driver");
  15. String first_name=request.getParameter("first_name");
  16. String password=request.getParameter("pass");
  17. conn=DriverManager.getConnection(DB_URL,username,password);
  18. st=conn.createStatement();
  19. String sql="select * from emp where first_name='"+first_name+"' and password='"+password+"';";
  20. res=st.executeQuery(sql);
  21. if(res==null)
  22. {
  23. out.println("Wrong password");
  24. System.exit(0);
  25. }
  26. String DisplayName;
  27. String DisplayLastName;
  28. String DisplayAccount;
  29. while(res.next())
  30. {
  31. DisplayName=res.getString("first_name");
  32. DisplayLastName=res.getString("last_name");
  33. DisplayAccount=res.getString("account_type");
  34. out.println("<table>");
  35. out.println("<tr><th>First Name</th><th>Last Name</th><th>Account Type</th></tr>");
  36. out.println("<tr><td>"+DisplayName+"</td><td>"+DisplayLastName+"</td><td>"+DisplayAccount+"</td></tr>");
  37. out.println("</table>");
  38. }
  39. }
  40. catch(ClassNotFoundException c)
  41. {
  42. c.printStackTrace();
  43. }
  44. catch(SQLException se)
  45. {
  46. se.printStackTrace();
  47. }
  48. }
Add Comment
Please, Sign In to add comment