AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Problem while iterating data through while(rs.next())

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java and Databases
View previous topic :: View next topic  
Author Message
Chetan Nehete via JavaKB.
Guest





PostPosted: Mon Mar 14, 2005 12:07 pm    Post subject: Problem while iterating data through while(rs.next()) Reply with quote



Hi guys,

am facing problem while iterating through while(rs.next()).

I want to retrive userid from my database through username criteria.
I wrote one simple query for that.
But after getting connection,statement and executing query,at the time of
entering while(rs.next()),it is giving problem,it is not entering into
while and that's why my value of userid is not not getting set into data
object.Consenquently,in further method calls the userid is going null,and
it's throwing NullPointerException.

I've provided code below,plz help me for the same.

thanx to all of u.


try
{
String sql = getQuery("SQL_SELECT_CTS_USERS_USER_ID");
//The query for above key is "Select * from CTS_USERS where upper(USERNAME)
= ?"
conn = ConnectionManager.getConnection();
pstmt=StatementFactory.getStatement(conn,sql);

if(ctsUserData.getUserName() != null && ctsUserData.getUserName().trim()
..length() > 0)
{
System.out.println("InvestigatorSessionBean.deleteFromLDAP() in if");
pstmt.setString(1,ctsUserData.getUserName().toUpperCase());
}
else
{
System.out.println("InvestigatorSessionBean.deleteFromLDAP() in the
else");
pstmt.setNull(1,Types.VARCHAR);
}
System.out.println("InvestigatorSessionBean.deleteFromLDAP() query is"
+pstmt);

rs=pstmt.executeQuery();
System.out.println("The resultset is"+rs);
while(rs.next())
{
ctsUserData.setUserId(new Long(rs.getLong("USER_ID")));
System.out.println("InvestigatorSessionBean.deleteFromLDAP() user id in
while "+ctsUserData.getUserId());
}
}
catch (Exception e)
{
e.printStackTrace();
msg = e.getMessage();
log(Priority.ERROR, msg);
throw new RemoteException(msg);
}
finally
{
ConnectionManager.cleanUp(conn, pstmt, rs);
}

--
Message posted via http://www.javakb.com
Back to top
Robert Klemme
Guest





PostPosted: Mon Mar 14, 2005 1:16 pm    Post subject: Re: Problem while iterating data through while(rs.next()) Reply with quote




"Chetan Nehete via JavaKB.com" <forum (AT) JavaKB (DOT) com> schrieb im Newsbeitrag
news:ad5830f011e64f618a59c79451da9c4c (AT) JavaKB (DOT) com...
Quote:
Hi guys,

am facing problem while iterating through while(rs.next()).

I want to retrive userid from my database through username criteria.
I wrote one simple query for that.
But after getting connection,statement and executing query,at the time
of
entering while(rs.next()),it is giving problem,it is not entering into
while and that's why my value of userid is not not getting set into data
object.Consenquently,in further method calls the userid is going
null,and
it's throwing NullPointerException.

Well, are you sure that the name is in the db? You could experience
either of two scenarios: no lines matching => user name never set. more
than one line matching => user name might be set multiple times and the
last one is NULL. Or you do something wrong with your bean, i.e. set the
data in one bean but accidentally use another one.

Quote:
I've provided code below,plz help me for the same.

Please use proper indentation.

<snip/>

Regards

robert


Back to top
ableofhighheart@gmail.com
Guest





PostPosted: Mon Mar 14, 2005 1:52 pm    Post subject: Re: Problem while iterating data through while(rs.next()) Reply with quote



Quote:
it is not entering into
while and that's why my value of userid is not not getting set into
data
object.

It is not entering into the while loop because the resultset is empty.
Try running your query outside of your Java program to verify that it
returns results.


Back to top
joeNOSPAM@BEA.com
Guest





PostPosted: Mon Mar 14, 2005 5:21 pm    Post subject: Re: Problem while iterating data through while(rs.next()) Reply with quote

Hi. There's nothing wrong with your code, as much of it as is shown.
SHow us the full stacktrace of the NullPointerException.
Joe Weinstein at BEA

Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java and Databases All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.