Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Servlets and Database (if(rs.isBeforeFirst()))

Posted on 2002-04-02
2
Medium Priority
?
348 Views
Last Modified: 2013-11-24
The if(rs.isBeforeFirst()) methods cannot be found, so the login page always the false statement even if the customer exist. I tried to use if(rs.next()) as suggested but the problem still remains.

Assistance required with examples

Thank You
0
Comment
Question by:wbmorapedi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 18

Expert Comment

by:bobbit31
ID: 6913461
what's the error message when you try rs.next() ?
0
 
LVL 3

Accepted Solution

by:
msterjev earned 280 total points
ID: 6913464
You alredy own me two unawarded questions. This is my last try:

I check this code and it works fine on tomcat:

HTML form:

<html>
<body>
<form METHOD=POST Action="servlet/LoginServlet">
USERNAME:<INPUT TYPE=TEXT Name="username"><BR>
PASSWORD<INPUT TYPE=PASSWORD NAME="password"><BR>
<INPUT TYPE=SUBMIT VALUE="LOGON">
</form>
</body>
</html>


LoginServlet.java

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.sql.*;


public class LoginServlet extends HttpServlet
{
   
   
    public void doPost(HttpServletRequest req,HttpServletResponse res) throws IOException,ServletException
    {
         Connection con=null;
         Statement stmt=null;
         ResultSet result=null;
         String username,password,stmtSQL;
         boolean logged=false;
         PrintWriter out=res.getWriter();
         res.setContentType("text/html");
         username=req.getParameter("username");
         password=req.getParameter("password");
         try
         {
              Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
              con=DriverManager.getConnection("jdbc:odbc:Imenik");
              stmt=con.createStatement();
              stmtSQL="Select * From Users Where username='"+username+"' and password='"+password+"'";
              result=stmt.executeQuery(stmtSQL);
              if(result.next())
                   logged=true;
              else
                   logged=false;
              stmt.close();
              con.close();
              con=null;
         }
         catch(Exception e)
         {
              e.printStackTrace();
         }
         finally
         {
              if(con!=null)
              {
                   try
                   {
                        con.close();
                   }
                   catch(Exception ignored){}
              }
         }
         if(logged)
              res.sendRedirect("http://localhost:8080/examples");
         else
              res.sendRedirect("http://localhost:8080/Log/index.html");
         
    }
}
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question