Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Exception! Column not found!?

 
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:
 
Yashnoo lyo
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can anyone can help me?Up! :roll:
 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 152
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mark Bensing :
You are right!I changed it and it works well.Thank you!
 
Mo-om! You're embarassing me! Can you just read a tiny ad like a normal person?
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic