• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

problem with ....while(rs.next())

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i'm trying to generate a reference but i cant seem to be getting it right
can somebody help me please
thanks

strSQL=("select max(complainantid) from complainant");
logger.info("SQL: "+strSQL);

try {
pstmt=cn.prepareStatement(strSQL);
rs=pstmt.executeQuery();
}
catch(Exception e)
{
logger.info("info :"+e);
}

try{

while(rs.next())
{
int Number=rs.getInt(1);
// int rowNum+=1;


%>
<script>alert("Your Reference Number is:<%=Number %>");</script>
<%

}
rs.close();

}catch(Exception e)
{
logger.info("After generating the sequence number:");
}
%>
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the behaviour you expect and what is the problem?
 
Kingsley Mullers
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Statement (strSQL) is supposed to return the maximun sequence number generated and i'm trying to print it out on the jsp... i think i'm messing up on the while.next... the max number is declared as an int.
 
Ranch Hand
Posts: 502
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What's the problem that you are facing? Are you getting exceptions? or the code executes but doesn't give any result

The only problem that I see is that if executeQuery generates an exception, rs will be null. You might want to move all your code inside a single try-catch block. That would save a lot of unnessescary operations and make your log much cleaner

Also, if you dont have any records in complainant, then nothing will come on the screen.

You can try this

 
Kingsley Mullers
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for the response...
i've done just that but no luck...
the code execute fine but no number is generated.
when i run my SQL statement(strSQL) on SQL navigator it works fine cos i do get the max number but on the jsp i dont .
 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maybe there is something wrong with the connection?
Padma
 
Kingsley Mullers
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for the response once again, i think the connection is fine.
what i do is , i insert into a table using sequence(sequence.nextval) as primary key then i select the maximum number(current value)and use this as the reference number. i then try to generate this number on my jsp but the number is not printed.
 
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Is this problem solved? If not, can you furnish what info is logged? My instinct tells me there is an exception somewhere that you overlook.

Probably the ResultSet is closed when you try to access it. Did you close the PreparedStatement anywhere in your code. Check that out. If you close the PreparedStatement, the ResultSet automatically gets closed.
 
Do not threaten THIS beaver! Not even with this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic