Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

showing exception: illegal operation on empty Result set

807591Jun 4 2008 — edited Jun 4 2008
Hi All,

I have a problem regarding ResultSet.Its showing exception while deploying as

Exception java.sql.SQLEXCEPTION: illegal operation on empty result set.
But i entered username and password already.when i am retriving it in mysql its displaying.But i dont know why its shoing exception.please help me regarding that..My program is as follows:


public boolean check(String loginname,String loginpwd)

{
try{

int i=0;
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","");
con.setAutoCommit(false);
Statement s=con.createStatement();
System.out.println("select password from user where username="+loginname); ResultSet rs=s.executeQuery("select password from user where username=' "+loginname+" ' System.out.println("pwd is.."+rs.getString(1));
while(rs.next())
{
if((rs.getString(1)).equals("loginpwd"))
{
System. out.println("username exist..............");
return true;
}
else
return false;
}
return true;
}

catch (Exception e)
{
System.out.println("Exception"+e);
return false;
}
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 2 2008
Added on Jun 4 2008
24 comments
4,005 views