Guest User

Untitled

a guest
Mar 16th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. import javax.servlet.http.*;
  2. import javax.servlet.*;
  3. import java.io.*;
  4. import java.sql.*;
  5.  
  6. public class abc extends HttpServlet{
  7. public void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException{
  8. res.setContentType("text/html");
  9. PrintWriter pw = res.getWriter();
  10. String id_passed = req.getParameter("id");
  11. String pass = req.getParameter("password");
  12.  
  13. //JDBC code goes here
  14. try{
  15. pw.println("<html><body>");
  16. pw.println("hello world");
  17. Class.forName("com.mysql.jdbc.Driver");
  18. Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/java","root","toor");
  19. Statement stmt = con.createStatement();
  20. ResultSet rs = stmt.executeQuery("SELECT * FROM admin");
  21. while(rs.next()){
  22. int id_fetched = rs.getInt("id");
  23. String name = rs.getString("name");
  24. pw.println("Welcome "+name);
  25. pw.println("</body></html>");
  26. pw.close();
  27.  
  28. }
  29. System.out.println("Connection sucessfull");
  30. }catch(SQLException i){
  31. i.printStackTrace();
  32. }catch(Exception e){
  33. e.printStackTrace();
  34. }
  35. //JDBC code ends here
  36.  
  37.  
  38. }
  39. }
Add Comment
Please, Sign In to add comment