Exception in thread "main" java.lang.NullPointerException

Hai,

When i complie the program it complied fine and when running my program i am getting this error.

basically ,

my code here is

public static void main (String args[])throws SQLException

{

String driverName = "com.mysql.jdbc.Driver";

String connectURL = "jdbc:mysql://localhost:3306/bhargavi";

Connection db = null;

try {

Class.forName(driverName);//Load the driver

db = DriverManager.getConnection(connectURL,"root","");//Establish the connection

Statement statement = db.createStatement();

--some select queries--

} catch (Exception e) {

System.err.println("Error creating class: "+e.getMessage());

} //end of try catch

finally {

System.out.println("Closing connections...");

try {

db.close();//closing the Database Connection.

} catch (SQLException e) {

System.err.println("Can't close connection");//Print the Error if database connection is not closed

}

can any one help me in tracing my problem

g

[1065 byte] By [kurra99a] at [2007-11-27 2:28:18]
# 1
you can do it yourself. the stack trace will tell you exactly what line the NPE is being thrown at. look at that line in your code editor, and ensure that all the objects being used on it actually exist
georgemca at 2007-7-12 2:40:10 > top of Java-index,Java Essentials,New To Java...
# 2
Yes,I am using the NetBeans 5.5it point out to closing connection of DBdb.close();
kurra99a at 2007-7-12 2:40:10 > top of Java-index,Java Essentials,New To Java...
# 3
then first check if db == null, before doing that call
georgemca at 2007-7-12 2:40:10 > top of Java-index,Java Essentials,New To Java...
# 4
i am not able to understand where the error . when i remove the db.close(); its catch error..
kurra99a at 2007-7-12 2:40:10 > top of Java-index,Java Essentials,New To Java...
# 5
Yes i have initilized the Connection db= null; if i remove null; i am getting again another error db variable not initilized
kurra99a at 2007-7-12 2:40:10 > top of Java-index,Java Essentials,New To Java...
# 6
Thank you in giving some important infothis i could finally retified just by adding if(db!=null)finally{if(db!=null){try{}catch{}}
kurra99a at 2007-7-12 2:40:10 > top of Java-index,Java Essentials,New To Java...