| Author |
Working with Temporary Table
|
Nazmul Bhuiyan
Greenhorn
Joined: May 23, 2002
Posts: 17
|
|
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??
|
 |
Avi Abrami
Ranch Hand
Joined: Oct 11, 2000
Posts: 1114
|
|
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
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. 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 Part of my code: System.out.println("SQL to get Cash Lodgement data : \n"+ sb.toString() +"\n"); getConnection(); Statement stmt = connection.createStatement(); rs = stmt.executeQuery(sb.toString()); System.out.println(" rs: "+ rs);
|
 |
SJ Adnams
Ranch Hand
Joined: Sep 28, 2001
Posts: 925
|
|
try stmt.execute(sb.toString()); rs = stmt.getResultSet(); HTH
|
 |
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
Greenhorn
Joined: May 23, 2002
Posts: 17
|
|
|
Yes you are right but my question is why the resultSet is unll?
|
 |
Dirk Schreckmann
Sheriff
Joined: Dec 10, 2001
Posts: 7023
|
|
Naz, 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. Jamie
|
 |
 |
|
|
subject: Working with Temporary Table
|
|
|