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 3 of 3

Thread: JDBC Problem - com.mysql.jdbc.Driver

  1. #1
    Junior Member
    Join Date
    Mar 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default JDBC Problem - com.mysql.jdbc.Driver

    I am trying to connect to my MySQL DB with JDBC but I am having a problem with my servlet. I have my Data Access Object class which is able to establish a connection with the db. In my servlet init() function, I try to establish a connection using my DAO class but I keep getting the error message "com.mysql.jdbc.Driver". I do not understand what is happening as this worked fine in the DAO class.


    Servlet.java
    private Dao dao = new Dao();
     
    public void init() {
     	dao.connectToDB();   	
    }

    Dao.java
    public  void connectToDB() {
        try {
            Class.forName ("com.mysql.jdbc.Driver").newInstance ();
            conn = DriverManager.getConnection (databaseURL, userName, password);
            System.out.println ("Database connection established");           
        } catch (Exception e) {
            System.err.println ("Cannot connect to database server");
            System.err.println ("Error message: " + e.getMessage());
        }  finally  {
            if (conn != null) {
                try {
                    conn.close ();
                    System.out.println ("Database connection terminated");
                } catch (Exception e) { }
            }
        }
    }


  2. #2
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: JDBC Problem - com.mysql.jdbc.Driver

    What is the exception message?
    Paste here so that we could look over it. Also give the details about your variables, i mean where are they declared and what are there datatypes and scope too.

  3. #3
    Junior Member
    Join Date
    Mar 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: JDBC Problem - com.mysql.jdbc.Driver

    Exception message: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

    I solved the problem.
    java - MySQL jdbc driver and Eclipse: ClassNotFoundexception com.mysql.jdbc.Driver - Stack Overflow

Similar Threads

  1. java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
    By i4ba1 in forum JDBC & Databases
    Replies: 2
    Last Post: August 23rd, 2011, 12:41 PM
  2. Cannot locate sun.jdbc.odbc.jbcOdbc driver
    By birdlover2010 in forum JDBC & Databases
    Replies: 7
    Last Post: November 6th, 2010, 02:57 PM
  3. setting JDBC driver steps
    By planmaster in forum JDBC & Databases
    Replies: 1
    Last Post: November 6th, 2010, 02:02 PM
  4. How to instal JDBC driver package in eclipse
    By sathish in forum JDBC & Databases
    Replies: 2
    Last Post: September 2nd, 2010, 10:09 AM
  5. How to install a JDBC driver in Eclipse? And where to take it from?
    By noFear in forum Java Theory & Questions
    Replies: 2
    Last Post: August 17th, 2010, 10:51 AM