f



jdbc connection to MS access database

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.

0
jinto12 (8)
5/24/2007 6:21:21 AM
comp.lang.java.databases 3049 articles. 0 followers. samyaksulabh (16) is leader. Post Follow

2 Replies
977 Views

Similar Articles

[PageSpeed] 42

"jinto12" <jinto12@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 


0
Bjorn
5/27/2007 6:54:59 AM
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
Indika
7/13/2007 3:23:05 AM
Reply: