Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Unable to get Statement Object.

 
Arun Boraiah
Ranch Hand
Posts: 233
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
One of the existing application which is used over a period of time causing a problem all of sudden.
When investigated i found the Statment object is not returned from the Connection object.
System.out.println("Connection is closed " +conn.isClosed() );
//isClosed() is returing false, which making me to belive connection is fine.
Statement st =conn.createStatement(); //st is null

What whould be possible reason createStatement method return null...
Thanks in advence for help....
 
Jignesh Gohel
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Arun,

System.out.println("Connection is closed " +conn.isClosed() );
//isClosed() is returing false, which making me to belive connection is fine


Instead of this one check out if (conn == null) if yes then conenction might not have established.

As per my knowledge u might not get the statement object because the connection object is not obtained,you can try out the check for connection object like above mentioned ie for null.
 
Arun Boraiah
Ranch Hand
Posts: 233
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jignesh,
Actually if connection was null, then when i tried createStatement() on connection object i should have got null pointer exception. However i tried your condition and i found that connection is not null.
Any other inputs....
Thanks
 
Jignesh Gohel
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Arun,

If u can , please paste some of ur code which is creating problem??
By looking at the code somebody can help u in less time.
 
Abhinav Gupta
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Arun,

Please specify the problem enviornment clearly.
Like which database, driver, App Server etc u are using ..
Becuase there may be some problem in the enviorment.
Also paste some code snipplet you are trying out..


thanks,
Abhinav
 
Arun Boraiah
Ranch Hand
Posts: 233
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,
Thanks for your response.
The problem is resolved, The cause for the problem was the classpath.
I mean the driver present in the classpath was not one expected. Hence on correcting the classpath, application is working fine.
Regards
Arun
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic