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 / September 2004

Tip: Looking for answers? Try searching our database.

jdbc getting started problem

Thread view: 
duxbuz - 26 Sep 2004 10:38 GMT
Unable to load database driver
Details: java.sql.SQLException: No suitable driver

This is an error I am getting after trying to make a database connection
with java to a access database. I added my database to the odbc system dsn.

I add the URL as an argument e.g java makeConnection myDatabase

I have read about 50 posts on this subject, i think i might be not
setting up the odbc system dsn right or sommat. I don't have to have a
third party driver do I.

Any help would be great.

Thanks

My code:
import java.net.URL;
import java.sql.*;
import sun.jdbc.odbc.*;

public class makeConnection {
   public static void main(String[] args) {
      if (args.length == 0) {
         System.out.println("java MyDB <url>");
         System.exit(1);
      }
      try {
         Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
         Connection con = DriverManager.getConnection(args[0]);
         Statement stmt = con.createStatement();
         ResultSet rs = stmt.executeQuery("SELECT FirstName,
LastName,Age FROM Table1");
         while(rs.next()) {
            String FirstName = rs.getString("FirstName");
            String LastName = rs.getString("LastName");
            int Age = rs.getInt("Age");
            System.out.println(FirstName + " " + LastName + " " + Age);
         }
         stmt.close();
         con.close();
      }
      catch (Exception x) {

}

    System.err.println ("Unable to load database driver");
    System.err.println ("Details : " + cnfe);
    System.exit(0);
}
      }
   }
}
duxbuz - 26 Sep 2004 10:58 GMT
> Unable to load database driver
> Details: java.sql.SQLException: No suitable driver
[quoted text clipped - 49 lines]
>    }
> }

Sorry I found solution, was not passing full argument:

was trying ---> c:\>java makeConnection myDatabase

should be ---> c:\>java makeConnection jdbc:odbc:myDatabase#

Works great now!


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.