actually the problem is in
-----------------------------------------------------------------------------------------
preparedForUser=con.prepareStatement("select Password
from UserMaster where UName='?' ");
preparedForUser.setString(1, userName);
-----------------------------------------------------------------------------------------
code. I changed preparedstatement like "select Password from UserMaster
where UName ='" + userName +"'" and placed in
-----------------------------------------------------------
res=preparedForUser.executeQuery();
-----------------------------------------------------------
and it worked ! So what was the problem.
Doesn't prepared statement support to varchar data type through java?
This problem occurs always ! it in fact
i then changed code to
-------------------------------------------
if(res.next)
extract data from res
else
return null
--------------------------------------------
here it doesn't chow any exception but no record.
Could you find it? I'm keen to know it.
UserDTO userDTO=null;
try {
if(isConnected) {
preparedForUser=null;
res=null;
String query ="select Password from UserMaster where
UName ='"+userName+"'" ;
preparedForUser=con.prepareStatement(query);
// preparedForUser.setString(1,"'" + userName+"'");
res=preparedForUser.executeQuery();
if(res.next()) {
userDTO=DTOFactory.getUserDTO(userName,
res.getString(1));
return userDTO;
}
} else {
connect();
throw new DatabaseException("Database is not Connected,
Try Again ");
}
} catch(DatabaseException de){
de.getMessageGUI();
} catch(SQLException se){
new DatabaseException(se.getMessage()).getMessageGUI();
} catch(Exception e){
new DatabaseException(e.getMessage()).getMessageGUI();
} finally{ System.runFinalization(); return userDTO;}
Joe Weinstein - 27 Feb 2006 17:10 GMT
> actually the problem is in
> -----------------------------------------------------------------------------------------
> preparedForUser=con.prepareStatement("select Password
> from UserMaster where UName='?' ");
> preparedForUser.setString(1, userName);
That's the problem. You shouldn't put a parameter marker in
quotes. It should be:
preparedForUser=con.prepareStatement("select Password from UserMaster where UName= ? ");
HTH,
Joe Weinstein at BEA Systems
> -----------------------------------------------------------------------------------------
> code. I changed preparedstatement like "select Password from UserMaster
[quoted text clipped - 43 lines]
> new DatabaseException(e.getMessage()).getMessageGUI();
> } finally{ System.runFinalization(); return userDTO;}