0

I am trying to connect Msaccess database with my java webapplication using the following code:

    import java.sql.*;
 public class connection {
 public static void main(String[] args) {
try {
// Load MS accces driver class
 Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  System.out.println("loaded");

  String url =  "jdbc:odbc:OnboardingTT";

   System.out.println("assigned");
  // specify url, username, pasword - make sure these are valid 
   Connection conn = DriverManager.getConnection(url,"","");

   System.out.println("Connection Succesfull");

  } catch (Exception e) {
 System.err.println("Got an exception! ");
  System.err.println(e.getMessage());


    }}}

But connection is not established. and the error is

    loaded 
    assigned
  Got an exception!
    null   
    java.lang.NullPointerException      
    at sun.jdbc.odbc.JdbcOdbcDriver.initialize(Unknown Source) at
    sun.jdbc.odbc.JdbcOdbcDriver.connect(Unknown Source) at  
    java.sql.DriverManager.getConnection(Unknown Source) at 
    java.sql.DriverManager.getConnection(Unknown Source) at   
    connect.connection.main(connection.java:18)

I also tried with

 String url = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb,*.accdb)};DBQ="+ "C:\\OnboardingTT.mdb";

Is this code correct or i have to do any changes in this please answer my question

  • 1
    Can you show the full error you got using `e.printStackTrace(System.err)`, the information you currently print isn't useful – Ferrybig Feb 16 '16 at 10:14
  • 1
    try by giving `e.printStackTrace()` in catch so that you will get to know what is the actual error.. – Anoop LL Feb 16 '16 at 10:14
  • Have you tried the url-only overload [DriverManager.getConnection(url)] instead of sending blank arguments? – ernest_k Feb 16 '16 at 10:22
  • `loaded assigned Got an exception! null java.lang.NullPointerException at sun.jdbc.odbc.JdbcOdbcDriver.initialize(Unknown Source) at sun.jdbc.odbc.JdbcOdbcDriver.connect(Unknown Source) at java.sql.DriverManager.getConnection(Unknown Source) at java.sql.DriverManager.getConnection(Unknown Source) at connect.connection.main(connection.java:18)` complete error I am getting is displayed above. – Saideepthi Anivireddi Feb 17 '16 at 08:26

1 Answers1

0

Looks like something went wrong with the DB connection, maybe the DB is not online, maybe the user or the password are incorrect...

Please provide more info to help us to help you.

;-)

SvOzMaS
  • 1
  • 2