Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: JDBC LoginServlet issues

  1. #1
    Junior Member
    Join Date
    Sep 2017
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default JDBC LoginServlet issues

    Hi all,

    I am new here, and new to java in general. I am taking my Java III class in college and have a project to make a web project with a login servlet for a bank. The login servlet takes the id and password you enter, checks the database, and returns HTML code Invalid or valid based on whether the ID and password match or not. That much I have working. However, if I enter a username and password that is not in the databse, I get a blank page instead of invalid login. I can not figure this out for the life of me. I meant to ask my teacher today, But with hurricane Irma being around class was cancelled. I am using ucanaccess for the databse driver in netbeans.

     protected void processRequest(HttpServletRequest request, HttpServletResponse response){
            response.setContentType("text/html;charset=UTF-8");
            try (PrintWriter out = response.getWriter()) {
                String id;
                String pw;
                String iddb="";
                String pwdb="";
                id = request.getParameter("idtd");
                pw = request.getParameter("pwtd");
                System.out.println(id);
                System.out.println(pw);
     
                //Load Driver
                Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
                String connURL="jdbc:ucanaccess://c:\\Users\\Bryan\\Desktop\\ChattBankMDB.mdb";
     
                //Get Connection
                Connection con = DriverManager.getConnection(connURL);
     
                //Create Statement
                Statement stmt = con.createStatement();
     
                //Execute Statement
                String sql;
                ResultSet rs;
                sql = "Select * from Customers where CustID = '"+id+"'";
                System.out.println(sql);
                rs = stmt.executeQuery(sql);
     
                rs.next();
                iddb = rs.getString("CustId");
                pwdb = rs.getString("CustPassword");
     
                System.out.println(iddb);
                System.out.println(pwdb);
     
                if (id.equals(iddb) && pw.equals(pwdb)){
                    out.println("<!DOCTYPE html>");
                    out.println("<html>");
                    out.println("<head>");
                    out.println("<title>ChattBank</title>");
                    out.println("</head>");
                    out.println("<body>");
                    out.println("<h1>Valid Login<h1>");
                    out.println("</body>");
                    out.println("</html>");
                }//end if
                else{
                    out.println("<!DOCTYPE html>");
                    out.println("<html>");
                    out.println("<head>");
                    out.println("<title>ChattBank</title>");
                    out.println("</head>");
                    out.println("<body>");
                    out.println("<h1>Invalid Login<h1>");
                    out.println("</body>");
                    out.println("</html>");
                }//end else
            }//end try
            catch(Exception e){
                System.out.println(e);
            }//end catch
        }//end process request[COLOR="Silver"]
    [/COLOR]


    --- Update ---

    Sorry. Everything is indented when I submit or try to edit. I am not sure why it isn't in the post.
    Last edited by bpeaceful; September 13th, 2017 at 02:03 PM.

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: JDBC LoginServlet issues

    Everything is indented when I submit or try to edit. I am not sure why it isn't in the post.
    The code needs to be wrapped in code tags:


    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.

    I get a blank page
    Where is the html for the blank page generated?

    What if there is an exception? Can you see the server's log to see if the catch block printed a message.
    Note: Call printStackTrace() in the catch block to get more info about any exception.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Sep 2017
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: JDBC LoginServlet issues

    Thanks, I fixed the code in my above post.

    There is no HTML for the blank page. The servlet is throwing an exception, I think, Which is causing the browser not to load any of the HTML I have supplied resulting in a blank page. I am pretty sure the exception is thrown only when my ResultSet returns nothing.
    The exception is: net.ucanaccess.jdbc.UcanaccessSQLException: UCAExc:::4.0.0 invalid cursor state: identifier cursor not positioned on row in UPDATE, DELETE, SET, or GET statement: ; ResultSet is empty

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: JDBC LoginServlet issues

    ResultSet is empty
    Sorry, I don't know anything about SQL.
    Does ResultSet have any methods to test for empty?



    Strange that the error message did not show the source line number where the exception happened. Does the code call the printStackTrace method?

    Should the catch block create an html page that shows the error?
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Please assist, issues with a JDBC connection
    By gmetz in forum JDBC & Databases
    Replies: 3
    Last Post: December 19th, 2012, 04:34 AM
  2. Issues with my ordering program - if statement issues?
    By Shenaniganizer in forum What's Wrong With My Code?
    Replies: 5
    Last Post: October 31st, 2012, 10:17 PM
  3. JDBC Problem - com.mysql.jdbc.Driver
    By icu222much in forum Java Servlet
    Replies: 2
    Last Post: November 21st, 2011, 11:54 PM
  4. JDBC
    By Abdul Rasheed in forum JDBC & Databases
    Replies: 1
    Last Post: August 13th, 2010, 07:01 AM