Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Databases / February 2006

Tip: Looking for answers? Try searching our database.

error in resultset

Thread view: 
Manoj Jain - 25 Feb 2006 09:40 GMT
public static UserDTO getUserDTO(String userName)
{
UserDTO userDTO=null; // a simple bean with username and password with
get-set methods
       try
       {
           if(isConnected)     //flag indicating database connectivity
           {
//preparedForUser is static and used once before for login
               preparedForUser=con.prepareStatement("select Password
from UserMaster where UName=?");
               preparedForUser.setString(1, userName);
               res=preparedForUser.executeQuery();

-----------------------------------------------
               res.next();        here it shows invalid cursor state
exception
----------------------------------------------
               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();    //showing exception in GUI
       }
       catch(SQLException se){
           new DatabaseException(se.getMessage()).getMessageGUI();
       }
       catch(Exception e){
           new DatabaseException(e.getMessage()).getMessageGUI();
       }
       finally{ return null;}
}
joeNOSPAM@BEA.com - 25 Feb 2006 15:51 GMT
Show the full actual stack trace of the exception that
JDBC method throws (not the DatabaseException you
create). Does this happen *every time*, or just some
of the time. If this code is ever run by multiple threads,
your problem is non-threadsafe code.
HTH,
Joe Weinstein at BEA
Manoj Jain - 27 Feb 2006 05:33 GMT
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;}


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.