0

Hi all,

i am new to java servlets. i simply created a login form with username and password fields. now when i deployed it on tomcat server, after i click on submit button it gives the following error:

java.sql.SQLException: Column not found

codin of this login servlet is attached below. i have used username,password,name and address fields in my table(database). i have created it using ms-access.
please reply asap!!!

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

public class Login extends HttpServlet
{
public void doGet(HttpServletRequest req,HttpServletResponse res) throws IOException,ServletException
{
PrintWriter p2=res.getWriter();
String s1=req.getParameter("txtusername");
String s2=req.getParameter("txtpass");

try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:ankit");
Statement stmt=con.createStatement();
String query="select username and password from Registeredusers";
ResultSet rs=stmt.executeQuery(query);

String password1;

while(rs.next())
{
if(s1.equals(rs.getString("username")))
{
if(s2.equals(rs.getString("password")))
{p2.println("<html>");
p2.println("<head>");
p2.println("<title>Logged in page</title>");

p2.println("</head>");
p2.println("<body bgcolor='lightblue'>");
p2.println("<p align='left'>");
p2.println("Hi <b>"+s1+"</b> Welcome to theStocks.com");

p2.println("</p>");
p2.println("<center>");
p2.println("<h1>Want to buy stocks</h1>");
p2.println("<a href='http://localhost:8080/ankit/'> Click here </a>");
}
else
{
p2.println("password did not match username");
}
}
else
{
p2.println("username did not match database");
}
}
stmt.close();
}
catch(Exception e)
{
p2.println(e);
}
}
}
2
Contributors
2
Replies
5
Views
7 Years
Discussion Span
Last Post by ankiwalia
2

Hi ankiwalia and welcome to Daniweb :)

Your SQL syntax is incorrect. Instead of this:

String query="select username and password from Registeredusers";

Try this:

String query="select username, password from Registeredusers";

Edited by darkagn: Welcome new member

0

thank you darkagn..that was really a help...i changed the syntax..and it worked fine!!!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.