Solved

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

Posted on 2002-04-02
2
333 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 70 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Custom Java Application connects to database: Which one of the 20? 4 41
Code Coverage and Coding Standards 2 49
Java List 4 41
Java array sort 10 35
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
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.

733 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