# JDBC connectivity with MS Access DB



## iamharish15 (May 2, 2011)

I am working on a project in which I need to store the information about the users into a Database and based on the querry I need to take the results from the databse and display the results retreived from database in a frame. But I could not put the retrieved information from the database into the frame and display it.
I am using J2SE JDK 1.6 and Netbeans 6.9.1 and MS Access(MS Office 2010 EE).
So please suggest the code or any other solution to it.


----------



## asingh (May 2, 2011)

I used to do it using AODB. But it supports JDBC too.

Use Microsoft Access with Java - JavaWorld
MS Access JDBC Driver -- Connecting MS Access with Java


----------



## iamharish15 (May 2, 2011)

this is not the problem i had. I had successfully connected with the access db using jdbc-odbc bridge but i am having trouble retrieving results from that database and display it on the frame or any output device.
for example the project i am working on requires me to take some specific tuples from the DB based on input criteria by the user(viz. firstname) and put it on a frame and displaying it.
Below is a code snippet i am having trouble with:


> private void PhoneDisplayActionPerformed(java.awt.event.ActionEvent evt) {
> try
> {
> Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
> ...


----------



## iamharish15 (May 3, 2011)

When I compiled the above code, it showed no errors but shows a run time exception.


> Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
> at sun.jdbc.odbc.JdbcOdbcPreparedStatement.clearParameter(JdbcOdbcPreparedStatement.java:1023)
> at sun.jdbc.odbc.JdbcOdbcPreparedStatement.setChar(JdbcOdbcPreparedStatement.java:3057)
> at sun.jdbc.odbc.JdbcOdbcPreparedStatement.setString(JdbcOdbcPreparedStatement.java:766)
> ...


When I run the static SQL select command through Statement object, it runs perfectly but when I try to take the parameter at runtime through PreparedStatement object, it shows the above exception.
Please suggest some solution for the above exception.


----------



## furious_gamer (May 4, 2011)

Did you checked the value "jComboBox7.getSelectedItem().toStri ng()" by printing it?


----------



## iamharish15 (May 4, 2011)

yes I have tried that it is working correctly.
static SQL commands are running good but the dynamic SQL commands with PreparedStatement object is having the trouble...


----------

