File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Exception! Column not found!? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Exception! Column not found!?" Watch "Exception! Column not found!?" New topic
Author

Exception! Column not found!?

Yashnoo lyo
Ranch Hand

Joined: Feb 17, 2003
Posts: 152
Hi everyone!
I have a login page and it send a request to a servlet.I want to search mydatabase to find if the name and the password exist.The table is "id int identity primary key,name varchar(200),password varchar(100),age int,email varchar(200),time datetime)".But when I click the login button in login.html and it says:java....Exception:column not found!My code is:
//////////////////login.java/////////////////////
public class login extends HttpServlet{
public void doPost(HttpServletRequest
request,HttpServletResponse response)throws
ServletException,IOException{
PrintWriter out=response.getWriter();
Properties prop=new Properties();
prop.put("user","sa");
prop.put("password","");
String cname=request.getParameter("name");
String sql="select password from registe where
name='"+cname+"'";
String uri="sun.jdbc.odbc.JdbcOdbcDriver";
String connectionStr="jdbc dbc:testxml";
try{
String
name=request.getParameter("name");
String
cpassword=request.getParameter("password");
ResultSet rs=null;
Statement stm=null;
Connection conn=null;
try{
Class.forName(uri);

conn=DriverManager.getConnection(connectionStr,prop);
stm=conn.createStatement();
rs=stm.executeQuery(sql);
while(rs.next()){
int id=rs.getInt("id");
String
name=rs.getString("name");
String
password=rs.getString("password");
String
age=rs.getString("age");
String
email=rs.getString("email");
Date
time=rs.getDate("time");
}
String password=rs.getString("password");
if(cpassword==password){
out.println("<html>");
out.println("<body>");

out.println("<h2>");
out.println("<font color=blue>");
out.println("Congratulations!You
login successfully!");
out.println("</font>");
out.println("</h2>");
out.println("</body>");
out.println("</html>");
}else{out.println("Sorry!Please check your
name or password,there is an error!");
}

out.close();
conn.close();
stm.close();
rs.close();
}catch(Exception e){

out.println(e.toString());}
:roll:
But I have the id,name,password,age,email,time exactly!Why it says column not found!??Please help me!Thank you! :roll:


When I face C# and Java I choose Java.
Yashnoo lyo
Ranch Hand

Joined: Feb 17, 2003
Posts: 152
Can anyone can help me?Up! :roll:
Mark Bensing
Ranch Hand

Joined: Mar 09, 2003
Posts: 40
You get the exception because the id, name, age, email and time columns are not in the select statment but you are trying to retrieve their values from the result set. Add these columns to your select statement.
Yashnoo lyo
Ranch Hand

Joined: Feb 17, 2003
Posts: 152
Hi Mark Bensing :
You are right!I changed it and it works well.Thank you!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exception! Column not found!?
 
Similar Threads
Servlet help
Servlet API 2.2
JSP Logout
else loop not working
java.sql.SQLException: Before start of result set?!