JDBC MS Acess connect DSN-less free

ravi_patankar
ravi_patankar used Ask the Experts™
on
I have jdk1.3 (installed from j2sdk1_3_0-win.exe) on Windows XP machine with office 2000 installed.
The Driver, present on system is Microsoft Access Driver (*.mdb) 4.00.6019.00

After compiling the code successfully, an exception is thrown as follows while running the class file:
Exception in thread "main" java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

Code is as follows:

import java.sql.*;
import java.io.DataInputStream;
import java.awt.*;

public class test
{
     public static void main(String args[]) throws Exception
     {
          //String url = "JDBC:ODBC:MySQLDSN";
          Statement stmt;
          // Attempt to load database driver
        try
             {
                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
                Connection con = DriverManager.getConnection("jdbc:odbc:;DRIVER=Microsoft Access Driver(*.mdb);DBQ=F:/Ravi/JDBC/Access/jdbc1.mdb","","");
                System.out.print(con);
                System.out.print("Connection done");
             }
           catch (ClassNotFoundException cnfe) // driver not found
             {
                System.err.println ("Unable to load database driver");
                System.err.println ("Details : " + cnfe);
                System.exit(0);
             }

          // Create a URL that identifies database
          // Here MySQLDSN is DSN
         
           
     }

}
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2016
Commented:
Give this a try:

String url = "jdbc:odbc:DRIVER={Microsoft Access Driver(*.mdb)};DBQ=F:\\Ravi\\JDBC\\Access\\jdbc1.mdb";
Connection con = DriverManager.getConnection(url, "", "");

Author

Commented:
Dear CEHJ: Thanks for the quick reply but same exception is thrown after applying the code change suggested by you.
Top Expert 2016

Commented:
Check the docs. Make sure that particular driver supports dsn-less. Try forward slashes.
Build an E-Commerce Site with Angular 5

Learn how to build an E-Commerce site with Angular 5, a JavaScript framework used by developers to build web, desktop, and mobile applications.

Mick BarryJava Developer
Top Expert 2010
Commented:
try:
"jdbc:odbc:;DRIVER=Microsoft Access Driver (*.mdb);DBQ=F:/Ravi/JDBC/Access/jdbc1.mdb";
ravi_patankar:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.

Commented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

- Split points between CEHJ and objects

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Venabili
EE Cleanup Volunteer

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial