Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.servlet.http.*;
- import javax.servlet.*;
- import java.io.*;
- import java.sql.*;
- public class MyServletDemo extends HttpServlet{
- Connection con = null;
- PreparedStatement ps = null;
- ResultSet rs = null;
- @Override
- public void init() throws ServletException {
- try {
- con = DriverManager.getConnection("jdbc:mySQL://remotemysql.com:3306/FIDYcLvqGh", "FIDYcLvqGh", "DJD2t0wUvR");
- } catch (SQLException e) {
- e.printStackTrace();
- }o
- }
- @Override
- public void destroy() {
- if (con != null) {
- try {
- con.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public void doGet(HttpServletRequest req, HttpServletResponse res)
- throws ServletException,IOException
- {
- // primul pas
- PrintWriter out = res.getWriter();
- out.println("<html>");
- out.println("<body>");
- String firma = req.getParameter("firma");
- Integer cod = Integer.parseInt(req.getParameter("cod_magazin"));
- try {
- String s = "select * from Stoc where firma = ? and cod_magazin = ?";
- ps = con.prepareStatement(s);
- ps.setString(1, firma);
- ps.setInt(2, cod);
- rs = ps.executeQuery();
- while (rs.next()) {
- out.println("<h1>" + rs.getString("firma") + rs.getString("produs") + "</h1>");
- }
- } catch (SQLException e) {
- System.out.println("eroare");
- }
- out.println("</body>");
- out.println("</html>");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement