Working with Temporary Table

Nazmul Bhuiyan

Greenhorn

Posts: 17

posted 13 years ago

Hi, 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: stmt.executeQuery(sb1.toString()); stmt.executeQuery(sb2.toString()); stmt.executeQuery(sb3.toString()); 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??

Naz, 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, Avi.

Nazmul Bhuiyan

Greenhorn

Posts: 17

posted 13 years ago

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. BUILD SUCCESSFUL Total time: 6 seconds C:\javaDevelopment\projects\gliInterfaces\dev>ant Buildfile: build.xml compile: [javac] Compiling 1 source file to C:\javaDevelopment\projects\gliInterfaces\dev\build\classes run: [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 entController.java:285) [java] at com.peace.interfaces.PSCashManagementController.process(PSCashManagementControlle r.java:101) [java] at com.peace.interfaces.PSCashManagementController.main(PSCashManagementController.j ava:73) [java] at java.lang.reflect.Method.invoke(Native Method) [java] at org.apache.tools.ant.taskdefs.ExecuteJava.run(ExecuteJava.java:208) [java] at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:150) [java] at org.apache.tools.ant.taskdefs.Java.run(Java.java:415) [java] at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:163) [java] at org.apache.tools.ant.taskdefs.Java.execute(Java.java:108) [java] at org.apache.tools.ant.Task.perform(Task.java:319) [java] at org.apache.tools.ant.Target.execute(Target.java:309) [java] at org.apache.tools.ant.Target.performTasks(Target.java:336) [java] at org.apache.tools.ant.Project.executeTarget(Project.java:1306) [java] at org.apache.tools.ant.Project.executeTargets(Project.java:1250) [java] at org.apache.tools.ant.Main.runBuild(Main.java:610) [java] at org.apache.tools.ant.Main.start(Main.java:196) [java] at org.apache.tools.ant.Main.main(Main.java:235) [java] Program run took 2 seconds. core: BUILD SUCCESSFUL Total time: 9 seconds

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

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. Jamie