Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Databases / July 2007

Tip: Looking for answers? Try searching our database.

jdbc connection to MS access database

Thread view: 
jinto12 - 24 May 2007 07:21 GMT
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 - 27 May 2007 07:54 GMT
"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
Indika.Kuruppu@gmail.com - 13 Jul 2007 04:23 GMT
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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.