Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Kingsley Mullers
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • 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:");
}
%>
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Jayesh Lalwani
Ranch Hand
Posts: 502
  • Mark post as helpful
  • send pies
  • 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
  • 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 .
 
Padma Lalwani
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Sravan Kumar
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic