It's not a secret anymore!
The moose likes JDBC and Relational Databases and the fly likes Working with Temporary Table 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 "Working with Temporary Table" Watch "Working with Temporary Table" New topic

Working with Temporary Table

Nazmul Bhuiyan

Joined: May 23, 2002
Posts: 17
I created few StringBuffer for my queryString:
StringBuffer sb = new StringBuffer(500);
StringBuffer sb1 = new StringBuffer(500);
StringBuffer sb2 = new StringBuffer(500);
StringBuffer sb3 = new StringBuffer(500);
And then executing these query as follows:
rs = stmt.executeQuery(sb.toString());
I am trying to create a temp table by the sb1 and updating the temp table by sb2 and sb3. Finally I am executing the sb.
I am not sure whether I am able to do this?
Is there any one can help??
Avi Abrami
Ranch Hand

Joined: Oct 11, 2000
Posts: 1141

Allow me to suggest that you first try it out yourself (if you haven't done so already). Then, if it fails, please provide details of the failure -- including whether it failed at compile time, or at run time, and the error message (and stack trace) you got.
After that, I may be able to help you (but no guarantees :-)
Good Luck,
Nazmul Bhuiyan

Joined: May 23, 2002
Posts: 17
It compiled fine and having the following error during runtime. If you see the following error then you will see resultSet is null.
It is giving me nullPointerException during closing the resulSet as there is nothing to close.
Total time: 6 seconds
Buildfile: build.xml
[javac] Compiling 1 source file to C:\javaDevelopment\projects\gliInterfaces\dev\build\classes
[java] SQL to get Cash Lodgement data :
[java] select * from tmp_pscmLDG order by lodgement_no;
[java] executing statement:.............
[java] rs.close() : null
[java] java.lang.NullPointerException
[java] at com.peace.interfaces.PSCashManagementController.writeCashLodgements(PSCashManagem
[java] at com.peace.interfaces.PSCashManagementController.process(PSCashManagementControlle
[java] at com.peace.interfaces.PSCashManagementController.main(PSCashManagementController.j
[java] at java.lang.reflect.Method.invoke(Native Method)
[java] at
[java] at
[java] at
[java] at
[java] at
[java] at
[java] at
[java] at
[java] at
[java] at
[java] at
[java] at
[java] at
[java] Program run took 2 seconds.
Total time: 9 seconds

Part of my code:
System.out.println("SQL to get Cash Lodgement data : \n"+ sb.toString() +"\n");
Statement stmt = connection.createStatement();
rs = stmt.executeQuery(sb.toString());
System.out.println(" rs: "+ rs);
SJ Adnams
Ranch Hand

Joined: Sep 28, 2001
Posts: 925
rs = stmt.getResultSet();

Andy Bowes
Ranch Hand

Joined: Jan 14, 2003
Posts: 171
Do you have the rs.close() in a 'finally' block ?
If so my guess is that an exception is being thrown within the 'try' block that then causes the finally section to be invoked which then leads to your null pointer exception. Try using the following c ode in the finally block:
if ( rs != null){
try {rs.close();} catch (Exception x){}
[ April 30, 2003: Message edited by: Andy Bowes ]

Andy Bowes<br />SCJP, SCWCD<br />I like deadlines, I love the whoosing noise they make as they go flying past - Douglas Adams
Nazmul Bhuiyan

Joined: May 23, 2002
Posts: 17
Yes you are right but my question is why the resultSet is unll?
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
Welcome to JavaRanch!
We ain't got many rules 'round these parts, but we do got one. Please change your display name to comply with The JavaRanch Naming Policy.
Thanks Pardner! Hope to see you 'round the Ranch!

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

could be throwing the SQLException in any of the 3 SQL statements prior to your query, in which case your resultset rs has not been created yet. During the Exception or finally block, you try to close the resultset which hasn't yet been initialized. Thus your NullPointerException. To avoid this, do as Andy suggested and check for null before closing it.
I agree. Here's the link:
subject: Working with Temporary Table
It's not a secret anymore!