File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes problem with  ....while( Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "problem with  ....while(" Watch "problem with  ....while(" New topic

problem with ....while(

Kingsley Mullers
Ranch Hand

Joined: Jan 14, 2005
Posts: 48
i'm trying to generate a reference but i cant seem to be getting it right
can somebody help me please

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

try {
catch(Exception e)
{"info :"+e);


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

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


}catch(Exception e)
{"After generating the sequence number:");
Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

What is the behaviour you expect and what is the problem?

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Kingsley Mullers
Ranch Hand

Joined: Jan 14, 2005
Posts: 48
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 the max number is declared as an int.
Jayesh Lalwani
Ranch Hand

Joined: Nov 05, 2004
Posts: 502
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

Joined: Jan 14, 2005
Posts: 48
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

Joined: Nov 02, 2004
Posts: 49
Maybe there is something wrong with the connection?
Kingsley Mullers
Ranch Hand

Joined: Jan 14, 2005
Posts: 48
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

Joined: Sep 11, 2005
Posts: 121

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.

keep smilin :: sravan<br /><a href="" target="_blank" rel="nofollow">I scribble here</a>
I agree. Here's the link:
subject: problem with ....while(
It's not a secret anymore!