aspose file tools*
The moose likes JDBC and the fly likes NullPointerException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "NullPointerException" Watch "NullPointerException" New topic
Author

NullPointerException

hesham katon
Ranch Hand

Joined: Dec 18, 2002
Posts: 82
Hello Everyone,
I have a class which working good at a server , then when i moved it to another server it generates NullPointerException at this line :
statement=con.createStatement();
it load the driver well , and create the connection , then the problem happend while creatStatement .
Do you have any Idea about that
Thanks alot


Hesham Katon<br />SCJP 1.2<br />SCWCD 1.4<br />Better to light a candle than to curse the darkness
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30510
    
150

Are you sure that it creates the connection ok? From your post, it looks like con is null. That would explain the null pointer exception.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Nagendra Prasad
Ranch Hand

Joined: Jul 11, 2002
Posts: 219
as mentioned in the previous post, connection could be null.
you could use some defensive coding here...
if (conn != null)
{
// process further
}else
{
// handle error gracefully.
}
while moving servers or working in such an env, (we have a similar one.. where we have to connect to more than one data source), it is useful to know agains which datasource connections are being attempted and with what parameters.
This could be included in the exception being thrown!


Best Regards,<br />Nagendra Prasad.
hesham katon
Ranch Hand

Joined: Dec 18, 2002
Posts: 82
Thanks alot .
You are right , connection was null .
so the problem now with :
connection = DriverManager.getConnection("jdbc:mysql://[hostname]/[dbname]?user=[username]&password=[password]");
it generates sql exception
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: NullPointerException