Win a copy of Svelte and Sapper in Action this week in the JavaScript 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

invalid column index

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All

i have login table , it contains ID, username, password columns. when i am trying to get username and pass using prepared statement, getting invalid column type.

please the code below


i tried with this also ps = con.prepareStatement("select * from login where username=? and password=?"); but no luck

could you please let me know to resolve this issue.

Thanks & Regards,
Krishna
 
Marshal
Posts: 25823
69
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your PreparedStatement has two places for parameters. Their numbers are 1 and 2. Your code uses 2 and 3.
 
krishna chadalawada
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thxs Dude..Now am able to connect database but it is not entering to while loop. could you please update me asap.

 
Sheriff
Posts: 22000
107
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

krishna chadalawada wrote:could you please update me asap.


Please EaseUp.

If your loop body is never executed that must mean that your query returns no results.
 
krishna chadalawada
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your reply Rob Spoor

DAO class:

public class loginDAO {
private String userName;
private String passWord;

public loginDAO(String name, String pass){

this.userName = name;
this.passWord = pass;

}

public boolean validateUser() throws SQLException, ClassNotFoundException {
String url = "jdbc:oracle:thin:@kris-PC:1521:orcl";
//int id = 0;
Connection con = null;
PreparedStatement stmt = null;
//Statement stmt = null;
//ResultSet rs = null;
boolean flag = false;
try{
Class.forName("oracle.jdbc.driver.OracleDriver");

String query = "select username,password from loginuser where username = ? and password= ?"; //= ? and password = ?";
con = DriverManager.getConnection(url,"scott","tiger");
//stmt = con.createStatement();
stmt = con.prepareStatement(query);
stmt.setString(1, userName);
stmt.setString(2, passWord);

ResultSet rs = stmt.executeQuery();
if(rs.next() == true){
System.out.println("you are in true");
flag = true;
}else{
System.out.println("you are in false");
flag = false;
}



}catch(SQLException e){
System.out.println("++++++"+e.getMessage());

}

System.out.println(flag);

return flag;

}

}


Action class:

public class LoginAction extends Action {
/*
* Generated Methods
*/

/**
* Method execute
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
* @throws Exception
*/
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {

LoginForm loginForm = (LoginForm)form;// TODO Auto-generated method stub


String userID = loginForm.getUserName();
String pass = loginForm.getPassWord();

loginDAO ld = new loginDAO(userID,pass);

boolean isLogin = ld.validateUser();

if(isLogin == true){
return mapping.findForward("sucess");

}else{
return mapping.findForward("failure");
}
}
}

please go through my code. i could not able to enter into if (rs.next())condition.
could you please let me know the reason and how can i enter into if loop?? plaese let me know asap


I want to do server side login validation so if you guys have any code please share with me


thanking you in advace.
 
krishna chadalawada
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please go through my code. i could not able to enter into if (rs.next())condition in DAo Class
 
Paul Clapham
Marshal
Posts: 25823
69
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's like Rob said. Your query returns zero records. If you want to produce a ResultSet for which rs.next() will return true (at least the first time you call it) then use a query which returns at least one record. In other words, not that query. Or perhaps that query with data which matches something in your database.
 
These are the worst of times and these are the best of times. And this is the best tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic