Hey lads,

Just have a small query here thats really bugging me. When details are entered by user and checked in database, the program should display one of two messages as seen below. When the details are entered correctly the welcome message displays correctly. However, when incorrect details are entered, the second message does not display. In fact, there is a blank screen. Anyone have any ideas?

<%ResultSet rs = stmt.executeQuery ("SELECT * from table where name='" + request.getParameter ("name")+"'");%>

    <%while (rs.next()){
    String st_id = rs.getString ("name");

    if(st_id.equals(request.getParameter ("name"))){

        out.print("Welcome " + request.getParameter ("name"));
     }else {
        out.print("Please try again.");
    }
    }
%>

Yes, this is a basic JSP/JDBC problem. It is exactly what you should not be doing. Learn what beans are and use them. Or, at least, the SQL JSTL tags.

Cheers for the condescending reply. Can anyone else with my problem?

It is not condescending, at all. Scriplets in your JSP is a mixing of the model and the view (and, quite probably, the control) and a maintenance nightmare. If you are going to do something, regardless of on what scale, you can at least attempt to do it right.

OK i have a limited knowledge of javabeans. I have created a javabean and created an instance of it in the code below.

<%DBConnection.getConnection();
Statement stmt = DBConnection.getConnection().createStatement();%>


<%
      String name = request.getParameter ("name");
      getBean john = new getBean(username);
%>

<%ResultSet rs = stmt.executeQuery ("SELECT * from table where name='" + john.getName()+"'");%>

    <%while (rs.next()){
    String st_id = rs.getString ("name");

    if(john.getName().equals(st_id))

        out.print("Welcome " + john.getName());         
    
     else
         out.print("Unknown user. Please try again.");
    }
%>

Is this what you mean by using beans. If so, my code still won't print out the 'unknown user' message when it should. Any ideas why? P.s I just took the relevant code.

You're still using scriptlets.
Until you stop doing that, you're getting no more help.

OK i have a limited knowledge of javabeans. I have created a javabean and created an instance of it in the code below.

Why don't you try to follow tutorial from top of JSP section about MVC2?

Peter, thanks a million. Just going through the jsp example now.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.