• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Working with Temporary Table

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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??
 
Ranch Hand
Posts: 1143
1
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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);
 
Ranch Hand
Posts: 925
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try
stmt.execute(sb.toString());
rs = stmt.getResultSet();

HTH
 
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Nazmul Bhuiyan
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes you are right but my question is why the resultSet is unll?
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic