Advertisement
Guest User

Untitled

a guest
Jun 12th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 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 MyServletDemo extends HttpServlet{
  7.  
  8. Connection con = null;
  9. PreparedStatement ps = null;
  10. ResultSet rs = null;
  11.  
  12. @Override
  13. public void init() throws ServletException {
  14. try {
  15. con = DriverManager.getConnection("jdbc:mySQL://remotemysql.com:3306/FIDYcLvqGh", "FIDYcLvqGh", "DJD2t0wUvR");
  16. } catch (SQLException e) {
  17. e.printStackTrace();
  18. }o
  19. }
  20.  
  21. @Override
  22. public void destroy() {
  23. if (con != null) {
  24. try {
  25. con.close();
  26. } catch (SQLException e) {
  27. e.printStackTrace();
  28. }
  29. }
  30. }
  31.  
  32. public void doGet(HttpServletRequest req, HttpServletResponse res)
  33. throws ServletException,IOException
  34. {
  35. // primul pas
  36. PrintWriter out = res.getWriter();
  37.  
  38. out.println("<html>");
  39. out.println("<body>");
  40.  
  41. String firma = req.getParameter("firma");
  42. Integer cod = Integer.parseInt(req.getParameter("cod_magazin"));
  43.  
  44. try {
  45. String s = "select * from Stoc where firma = ? and cod_magazin = ?";
  46. ps = con.prepareStatement(s);
  47. ps.setString(1, firma);
  48. ps.setInt(2, cod);
  49.  
  50. rs = ps.executeQuery();
  51.  
  52. while (rs.next()) {
  53. out.println("<h1>" + rs.getString("firma") + rs.getString("produs") + "</h1>");
  54. }
  55. } catch (SQLException e) {
  56. System.out.println("eroare");
  57. }
  58.  
  59. out.println("</body>");
  60. out.println("</html>");
  61. }
  62.  
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement