| Author |
Establishing Connection to MS Access Databases
|
Ravi Magod
Greenhorn
Joined: Mar 04, 2005
Posts: 1
|
|
Hello ! I have been trying to establish a connection to a MS Access Database within my system. I am getting an error of " No driver" the piece of code is import java.sql.*; public class DriverManagerDemo { public DriverManagerDemo() { } public static void main(String[] args) { String url="F:/Javfiles/JavaRavi/Listner/JavaTrial.mdb"; System.out.println(" Attempting to connect to "+url); try{ System.out.println("Loading the driver ..."); Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); System.out.println("Establishing a Connection .."); Connection C=DriverManager.getConnection(url); Connection conn = DriverManager.getConnection("jdbc : odbc:" +url); System.out.println("Connect to "+C.getCatalog()+" a success"); } catch(Exception e){ e.printStackTrace(); } } } I get this error Attempting to connect to F:/Javfiles/JavaRavi/Listner/JavaTrial.mdb Loading the driver ... Establishing a Connection .. java.sql.SQLException: No suitable driver at java.sql.DriverManager.getConnection(DriverManager.java:532) at java.sql.DriverManager.getConnection(DriverManager.java:193) at DriverManagerDemo.main(DriverManagerDemo.java:28) Can anyone help in sorting this out? regards Ravi Magod
|
 |
Adi Peyyala
Greenhorn
Joined: Jan 17, 2005
Posts: 6
|
|
Ravi, Try doing this with your piece of code Connection c=DriverManager.getConnection(url,"",""); //Connection conn = DriverManager.getConnection("jdbc : odbc:" +url); System.out.println("Connect to "+c.getCatalog()+" a success"); I think the problem with you code lies in not having specified the username and password fields in the getConnection(). They should be left blank as show above. Best of Luck Adi.
|
 |
Anandh Ramesh
Ranch Hand
Joined: Dec 15, 2004
Posts: 61
|
|
hi, did you try using a dsn for this purpose? i guess that should do the trick.
|
cheers,<br />Anandh
|
 |
Tom Blough
Ranch Hand
Joined: Jul 31, 2003
Posts: 263
|
|
Connection conn = DriverManager.getConnection("jdbc : odbc:" +url);
Your problem is the spaces around the ":" between jdbc and odbc.
|
Tom Blough<br /> <blockquote><font size="1" face="Verdana, Arial">quote:</font><hr>Cum catapultae proscriptae erunt tum soli proscripti catapultas habebunt.<hr></blockquote>
|
 |
Joe Myn
Greenhorn
Joined: Oct 19, 2004
Posts: 25
|
|
Hello Ravi, Have you registered your database as an ODBC database. If you did that try using the database name instead of the url. example : connection = DriverManager.getConnection( "jdbc dbc atabaseName", "", "" ); [ March 12, 2005: Message edited by: Joe Myn ]
|
 |
 |
|
|
subject: Establishing Connection to MS Access Databases
|
|
|