• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NullPointerException

 
Renuka Kilambi
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am trying to connect an access database using jdbcodbc drivers.
The compilation is going on cleanly. But well I am running , the following is coming
Exception occured during event dispatching .java.lang.NullPointerException.

The code is as follows
Connection a_connection = null;
Statement a_statement = null;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException c){
}
try{
a_connection = DriverManager.getConnection("jdbc dbc:addresses","","");
}
catch(SQLException s){
}
try{
a_statement = a_connection.createStatement();
ResultSet result_set = a_statement.executeQuery("INSERT INTO ADDRESSES VALUES('Michelle','willieam','123','','','','','','','',''");
}
catch(SQLException q){
}
Could anybody please help me?
thanks in advance
Renuka
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.,
Ur mentioned code is
ResultSet rs = stmt.executeQuery("insert into .........");
But suppose if u want to go for update/delete/insert operations
u have to use executeUpdate() method. The return object is not
the resultset.
The correct syntax is
stmt.executeUpdate("insert into tablename values ( ));
The following command will give the number of updated/inserted/deleted rows.
System.out.println(stmt.getUpdateCount()).
 
Renuka Kilambi
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,
I tried excuteUpdate also.But I am getting the same error. can somebody help me.
Thanks
Renuka
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<html>HI
I think second time also you tried like this
ResultSet result_set = a_statement.executeUpdate("INSERT INTO ADDRESSES VALUES('Michelle','willieam','123','','','','','','','',''");
}
catch(SQLException q){
}

Here you will not have any result set thats why you are getting that Exception.Try it as following
a_statement.executeUpdate("INSERT INTO ADDRESSES VALUES('Michelle','willieam','123','','','','','','','',''");
}

</html>
Even then if you had the problem , please post the message
 
Renuka Kilambi
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Surya,
The second time I tried as
a_statement.executeUpdate("INSERT INTO ADDRESSES VALUES('Michelle','willieam','123','AVENEL','NJ','USA','07001','','','',''");
still I am getting the same error
any idea/
thanks
Renuka
 
Carl Trusiak
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try adding some debug statments to show where things are going wrong. You may not be establishing a connection and nothing in your code will show that
Connection a_connection = null;
Statement a_statement = null;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException c){
System.out.println("Error on Class Load : " + c);
}
try{
a_connection = DriverManager.getConnection("jdbc dbc:addresses","","");
} catch(SQLException s){
System.out.prinln("Error on Get Connection : " + s);
}
try{
a_statement = a_connection.createStatement();
int count = a_statement.executeQuery("INSERT INTO ADDRESSES VALUES('Michelle','willieam','123','','','','','','','',''");
System.out.println("Rows inserted : " + count);
} catch(SQLException q){
System.out.println("SQL Error on Execute Query : " + q);
}
catch(Exception ex)
{
System.out.println("Exception : " + ex);
}

This will give you more information to tell what is happening.
Please keep us posted
Good Luck

[This message has been edited by Carl Trusiak (edited September 20, 2000).]
 
Renuka Kilambi
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I inserted the debugging statements.You are right. The connection is not established.
I got the following error message.
Error on Get Connection : java.sql.SQLException: [Microsoft][ODBC Driver Manager
] Data source name not found and no default driver specified
Exception : java.lang.NullPointerException
Any advice is greately appreciated.
Renuka
 
Carl Trusiak
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to configure the ODBC data source for your access database. Microsoft should have examples on their site to help you with this.
Good luck
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try adding the following catch statements to your java/jdbc code.
<code>
// load driver
catch(ClassNotFoundException e) {
System.out.println("ClassNotFoundException!!!: " + e);
}
// sql sqlcode
catch(SQLWarning e) {
System.out.println("SQL_CODE !!!: " + e);
}
// sql class
catch(SQLException e) {
System.out.println("SQL_CLASS !!: " + e);
</code>
Hope this helps, Monty6
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic