Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

jdbc connection to MS access database

24 views
Skip to first unread message

jinto12

unread,
May 24, 2007, 2:21:21 AM5/24/07
to
Im trying to connect my database. im using ms access when i try to
execute my program it gives me this error
i create my database by going to the odbc in the administrative tools.
and when i try to execute my code it gives me this error:
java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getConnection(DriverManager.java:545)
at java.sql.DriverManager.getConnection(DriverManager.java:193)
at Transit.main(Transit.java:16)

and this is the code im using.

try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(Exception e){
e.printStackTrace(System.err);
}
Connection con;
Statement stmt;

//connecting to the database.
try{
con=DriverManager.getConnection("jbdc:odbc:Hw3");//this is where
its giving me errors
stmt=con.createStatement();

con.close();
stmt.close();
}
catch(Exception sqle){
sqle.printStackTrace(System.err);
}
any suggestions do i have to download any updates or something im
using java 1.5 sdk.

Bjorn Abelli

unread,
May 27, 2007, 2:54:59 AM5/27/07
to

"jinto12" <jin...@gmail.com> wrote...

> Im trying to connect my database. im using ms access when i try to
> execute my program it gives me this error
> i create my database by going to the odbc in the administrative tools.
> and when i try to execute my code it gives me this error:
> java.sql.SQLException: No suitable driver

[snip]

> con=DriverManager.getConnection("jbdc:odbc:Hw3");

Look closely on how you have spelled "jdbc"...

> any suggestions do i have to download any updates or something im
> using java 1.5 sdk.

Configuring a dsn in Windows, and relying on that dsn-name in your code, can
make your app less portable, than when calling the driver in a more "direct"
way.

Short example:

String url =
"jdbc:odbc:DRIVER={Microsoft Access Driver (*.mdb)};DBQ=mydb.mdb";

Connection con = DriverManager.getConnection (url);


/// Bjorn A


Indika....@gmail.com

unread,
Jul 12, 2007, 11:23:05 PM7/12/07
to
jinto12

Try This connection and update me

try

{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String dataSourceName = "Address.mdb";
String dbURL = "jdbc:odbc:Driver={Microsoft Access
Driver (*.mdb)};DBQ=";
dbURL += dataSourceName +
";DriverID=22;READONLY=true)";
dbconn = DriverManager.getConnection(dbURL,"","");
Statement s = dbconn.createStatement();
}


catch ( ClassNotFoundException cnfex )

{
cnfex.printStackTrace();
info=info+"Connection unsuccessful\n" + cnfex.toString();
}


Indika

0 new messages