SHARE
TWEET

Untitled

samkopite Apr 1st, 2019 38 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.io.IOException;
  2. import java.io.PrintWriter;
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.PreparedStatement;
  6. import java.sql.ResultSet;
  7. import java.sql.SQLException;
  8. import javax.servlet.ServletException;
  9. import javax.servlet.http.HttpServlet;
  10. import javax.servlet.http.HttpServletRequest;
  11. import javax.servlet.http.HttpServletResponse;
  12. public class retrieveservlet extends HttpServlet {
  13. String str;
  14. @Override
  15. protected void doGet(HttpServletRequest request,
  16. HttpServletResponse response)
  17. throws ServletException, IOException {
  18. response.setContentType("text/html;charset=UTF-8");
  19. try (PrintWriter out = response.getWriter()) {
  20. try
  21. {
  22. Class.forName("com.mysql.jdbc.Driver");
  23. Connection con =
  24. DriverManager.getConnection("jdbc:mysql://localhost:3306/name","root
  25. ","");
  26. PreparedStatement statement = con.prepareStatement("select * from
  27. name");
  28. ResultSet rs = statement.executeQuery();
  29. while(rs.next())
  30. {
  31. str=str+ "<table border='1'>
  32. <tr><td>"+rs.getString(1)+"</td><td>"+rs.getString(2)+"</td></tr>";
  33. }
  34. str=str+"</table>";
  35. out.println(str);
  36. }catch(ClassNotFoundException | SQLException e ){}
  37. out.println("<h1> Sucess on retrieval</h1>");
  38. }
  39. }}
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top