Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class DashBoard extends HttpServlet
- {
- public static final String DB_URL="jdbc:mysql://localhost/TEST";
- public static final String username="root";
- public static final String password="your-password";
- Connection conn=null;
- Statement st=null;
- ResultSet res=null;
- public void doGet(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException
- {
- PrintWriter out=response.getWriter();
- try
- {
- Class.forName("com.mysql.jdbc.Driver");
- String first_name=request.getParameter("first_name");
- String password=request.getParameter("pass");
- conn=DriverManager.getConnection(DB_URL,username,password);
- st=conn.createStatement();
- String sql="select * from emp where first_name='"+first_name+"' and password='"+password+"';";
- res=st.executeQuery(sql);
- if(res==null)
- {
- out.println("Wrong password");
- System.exit(0);
- }
- String DisplayName;
- String DisplayLastName;
- String DisplayAccount;
- while(res.next())
- {
- DisplayName=res.getString("first_name");
- DisplayLastName=res.getString("last_name");
- DisplayAccount=res.getString("account_type");
- out.println("<table>");
- out.println("<tr><th>First Name</th><th>Last Name</th><th>Account Type</th></tr>");
- out.println("<tr><td>"+DisplayName+"</td><td>"+DisplayLastName+"</td><td>"+DisplayAccount+"</td></tr>");
- out.println("</table>");
- }
- }
- catch(ClassNotFoundException c)
- {
- c.printStackTrace();
- }
- catch(SQLException se)
- {
- se.printStackTrace();
- }
- }
Add Comment
Please, Sign In to add comment