Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: Missing drivers?

  1. #1
    Member
    Join Date
    Jun 2010
    Posts
    75
    Thanks
    7
    Thanked 1 Time in 1 Post

    Default Missing drivers?

    I'm a little confused. The fololwing code compiles without error:

    import java.net.*;
    import java.sql.*;
    import java.io.*;
    import java.util.*;
     
    class MakeDB
    {
         public static void main (String args[])
         {
              try
              {
                   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); // force loading of driver
                   String url = "jdbc:odbc:BIBLIO";
                   String user = "";
                   String password = "";
                   Connection con = DriverManager.getConnection(url,user,password);
                   Statement stmt = con.createStatement();
                   ResultSet r=stmt.executeQuery("SELECT TITLE,AUTHOR FROM TITLES, AUTHORS WHERE TITLES.AU_ID=AUTHORS.AU_ID AND AUTHORS.AU_ID<10");
                   while(r.next())
                   {
                        String s1=r.getString("title");
                        String s2=r.getString("AUTHOR");
                        System.out.println(s1+ " "+s2);
                   }
                   stmt.close();
                   con.close();
             }
             catch (Exception ex)
             {
                  System.out.println ("Exception "+ex);
             }
         }
    }

    However, when I try to run it throws an exception:

    Exception java.lang.ClassNotFoundException: jdbc.odbc.JdbcOdbcDriver

    And when I replace jdbc.odbc.JdbcOdbcDriver with a driver I know I have, such as Sun.JavaDB.javadoc.jdbc3.org.apache.derby.jdbc.Emb eddedDriver, it throws this exception:

    Exception java.lang.ClassNotFoundException: Sun.JavaDB.javadoc.jdbc3.org.apache.derby.jdbc.EmbeddedDriver
    .

    Am I missing something basic about the packages that the JDBC drivers?


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Missing drivers?

    Are the driver packages on your classpath? If not, you need to add them to the classpath (eg let the jvm know where the packages are), which is typically IDE dependent.

  3. #3
    Member
    Join Date
    Jun 2010
    Posts
    75
    Thanks
    7
    Thanked 1 Time in 1 Post

    Default Re: Missing drivers?

    I'm just using Notepad and the command line.

    I'm not sure how to add packages to my classpatth.

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Missing drivers?


  5. The Following User Says Thank You to copeg For This Useful Post:

    mjpam (September 6th, 2010)

  6. #5
    Member
    Join Date
    Jun 2010
    Posts
    75
    Thanks
    7
    Thanked 1 Time in 1 Post

    Default Re: Missing drivers?

    Can I have it included in the standard package by moving the directory where the standard packages are located?

  7. #6
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Missing drivers?

    Try it and see. If I understand you correctly and you mean to add it where the standard jdk jar's reside, if your app is a distributed one, you usually want the jar's explicitely associated with the project since doing so make it easier to 'run anywhere'. IDE's make doing this a lot easier, where you add a jar to a project and the classpath is immediately set and the jar's can be packaged and distributed together

Similar Threads

  1. Missing Substance file
    By ma05k1 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: April 4th, 2010, 05:22 PM
  2. Prime number generator program missing return statement
    By 03EVOAWD in forum What's Wrong With My Code?
    Replies: 13
    Last Post: September 10th, 2009, 09:17 AM
  3. Error of "Class has no return statement"
    By mdstrauss in forum What's Wrong With My Code?
    Replies: 7
    Last Post: August 2nd, 2009, 12:00 PM
  4. Java error in password generator program
    By Lizard in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 16th, 2009, 07:49 PM
  5. [SOLVED] Java program to generate 10 random integers and then sum computed
    By Lizard in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 14th, 2009, 12:33 PM