• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Establishing Connection to MS Access Databases

 
Ravi Magod
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

did you try using a dsn for this purpose? i guess that should do the trick.
 
Tom Blough
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Connection conn = DriverManager.getConnection("jdbc : odbc:"
+url);


Your problem is the spaces around the ":" between jdbc and odbc.
 
Joe Myn
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic