0
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package bean;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Locale;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author hp
 */
@WebServlet(name = "Getdetails", urlPatterns = {"/Getdetails"})
public class Getdetails extends HttpServlet {

    /**
     * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
     * methods.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        try (PrintWriter out = response.getWriter()) {
            /* TODO output your page here. You may use following sample code. */
            Connection con = null;
            PreparedStatement ps = null;
            Statement st = null;
            ResultSet rs = null;
            String debitcard = new String();
            String debitcardno = new String();
            String accountno = new String();
            String account = new String();
            String cvv = new String();
            String pin = new String();

            try {
                Class.forName("com.mysql.jdbc.Driver");
                con = DriverManager.getConnection("jdbc:mysql://localhost:3306/bussinesssolutions?zeroDateTimeBehavior=convertToNull", "root", "root");
                ps = con.prepareStatement("select card.debitcardno, card.accountnno, card.cvv, card.pin from card inner join regsiter on card.edebitcardno = regsiter.debitcardno");
                ps.setString(1, debitcard);
                ps.setString(2, account);
                ps.setString(3, cvv);
                ps.setString(4, pin);
                rs = ps.executeQuery();
                debitcardno = rs.getString("debitcardno");
                accountno = rs.getString("accountno");
                cvv = rs.getString("cvv");
                pin = rs.getString("pin");

                request.getSession().setAttribute("debitcardno", debitcardno);
                request.getSession().setAttribute("accountno", accountno);
                request.getSession().setAttribute("cvv", cvv);
                request.getSession().setAttribute("pin", pin);
                RequestDispatcher rd = request.getRequestDispatcher("Getdetails");
                rd.forward(request, response);
            } catch (ClassNotFoundException | SQLException | ServletException | IOException e) {
                out.print(e);
            } finally {
                if (con != null) {
                    try {
                        con.close();
                    } catch (SQLException ex) {
                        Logger.getLogger(Bankdetails.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
                try {
                    ps.close();
                    st.close();
                } catch (SQLException ex) {
                    Logger.getLogger(Bankdetails.class.getName()).log(Level.SEVERE, null, ex);
                }
                try {
                    rs.close();
                } catch (SQLException ex) {
                    Logger.getLogger(Bankdetails.class.getName()).log(Level.SEVERE, null, ex);
                }
            }

        }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Handles the HTTP <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        `return` "Short description";
    }// </editor-fold>

}

I am getting the above mentioned exception. Don't know why.why such exception is occurring and how to resolve it. I want to fetch the details from the database of the above details but maybe some mistake in code that it is not happening

4
  • 1
    You've included a lot of code that isn't relevant, but haven't included the exception itself, with a full stack trace, indicating which line in your code is causing the error... Commented Feb 12, 2015 at 18:50
  • "select * from regsiter where username=? and password=?" is there a table actually named regsiter and not register? Commented Feb 12, 2015 at 18:51
  • @Compass I m sorry please check out the new code...just posted Commented Feb 12, 2015 at 18:52
  • @PratikGhosh - Still shows regsiter :) Commented Feb 12, 2015 at 18:54

1 Answer 1

1
ps = con.prepareStatement("select card.debitcardno, card.accountnno, card.cvv, " + 
    "card.pin from card inner join regsiter on card.edebitcardno = regsiter.debitcardno");

There's no ? parameters in this statement. None of the following would work.

ps.setString(1, debitcard);
ps.setString(2, account);
ps.setString(3, cvv);
ps.setString(4, pin);

You need to actually provide parameters to assign.

ps = con.prepareStatement("select card.debitcardno, card.accountnno, card.cvv, " + 
    "card.pin from card inner join regsiter on " + 
    "card.edebitcardno = regsiter.debitcardno " + 
    "where card.debitcardno=? AND card.accountno=? AND card.cvv=? AND card.pin=?");
Sign up to request clarification or add additional context in comments.

5 Comments

@PratikGhosh A where statement?
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.pin from card inner join regsiter on " + "card.edebitcardno = regsiter.deb' at line 1 it shows this now
@PratikGhosh that'd be something on your end, I can't see your DB schema. I'm sure you can fix it pretty easily.
java.sql.SQLException: Illegal operation on empty result set ....................................this is what i wrote ...................................... select card.debitcardno, card.accountnno, card.cvv, card.pin from card inner join regsiter on card.edebitcardno = regsiter.debitcardno where card.debitcardno=? and card.accountnno=? and card.cvv=? and card.pin=?
If you have a new problem, please ask it in a new prompt.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.