This week's book giveaways are in the Cloud/Virtualization and Go forums.
We're giving away four copies each of Cloud Native Transformation: Practical Patterns for Innovation and The Go Workshop and have the authors on-line!
See this thread and this one for details.
Win a copy of Cloud Native Transformation: Practical Patterns for InnovationE this week in the Cloud/Virtualization forum
or The Go Workshop in the Go 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
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Henry Wong
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Joe Ess
  • salvin francis

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: 24811
60
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: 21836
105
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: 24811
60
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.
 
Opportunity is missed by most people because it is dressed in overalls and looks like work - Edison. Tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!