Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I just got some errors in my Java oracle connectivity. Could anyone please help me with this? I have enclosed the code below. I'm getting this error:

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

this is the code

package md5IntegrityCheck;    
import java.sql.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;

public class MD5IntegrityCheck
{
  public static void main(String[] args)

  {

            String fileName,Md5checksum ,sql;

            Connection con;
            PreparedStatement pst;
            Statement stmt;
            ResultSet rs;

                    try{
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            Connection con1 =DriverManager.getConnection("jdbc:odbc:RecordTbl","scott","tiger");
                    }
            catch(Exception ee)
            {ee.printStackTrace( );}




            setDefaultCloseOperation(EXIT_ON_CLOSE);

                    }

                    /****insert method******/






        private static void setDefaultCloseOperation(String exitOnClose) {
        // TODO Auto-generated method stub

    }

                    static void setVisible(boolean b) {
        // TODO Auto-generated method stub


    try{


                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");  
                Connection con = DriverManager.getConnection("jdbc:odbc:RecordTbl","scott","tiger");
                        PreparedStatement pst = con.prepareStatement("insert into RecordTbl values(?,?)");
                String fileName = null;
                pst.setString(1,fileName);
                String Md5checksum = null;
                pst.setString(2,Md5checksum);

                int i=pst.executeUpdate( );

                System.out.println("recorded in database");
                con.close( );
                        }
                catch(Exception ee)
                {ee.printStackTrace( );}
                    }



                }   

    if (args.length <= 0)
    {
      Md5Gui gui = new Md5Gui();
      gui.runGui();
    }
    else
    {
      DoWork runningProgram = new DoWork();
      runningProgram.run(args);
    }
  }
}
share|improve this question
did you provided oracle drivers in class path – developer May 20 '11 at 8:18
Have you got the MySQL JDBC library in your lib folder / class path. – Mikaveli May 20 '11 at 8:19
possibilty duplicate stackoverflow.com/q/2591505/668970 – developer May 20 '11 at 8:33

3 Answers

Your question is vague:

In your exception, you're getting a ClassNotFoundException for a driver that pertains to MySQL. On your code, you're using a JDBC-ODBC Driver.

My suggestion is how did you configure your database connectivity. Let's start from there. Also, it would be better to add the exception stack trace to see exactly what's happening.

Edit: Visit this example if you want to know how to configure JDBC connection to Oracle Database. I fully recommend using the Oracle JDBC driver directly instead of connecting it to an ODBC Bridge.

share|improve this answer
that is not for mysql, its oracle drivers – developer May 20 '11 at 8:21
@Damodar, the com.mysql.jdbc.Driver pertains to the MySQL RDBMS and not Oracle Driver. – Buhake Sindi May 20 '11 at 8:23
can't u correct that code regarding odbc? – user762357 May 20 '11 at 8:25
but he is implementing for oracle driver in his code Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con1 =DriverManager.getConnection("jdbc:odbc:RecordTbl","scott","tiger");. Also he mentioned tag as oracle – developer May 20 '11 at 8:26
@Damodar, yes he did...but the OP never used Oracle Driver in any instance. sun.jdbc.odbc.JdbcOdbcDriver is not an Oracle DB driver and neither is com.mysql.jdbc.Driver (which is MySQL Driver). The OP should use the correct driver. His/Her code is wrong when connecting with JDBC. That's what I'm trying to say. – Buhake Sindi May 20 '11 at 8:28
show 11 more comments

You should look into any 3rd party library you're using whether there a MySQL database driver is needed. Although you write you are using an Oracle driver (though the JdbcOdbcDriver is provided by Java itself and has nothing to do with Oracle DB's) the exception is clearly stating that the MySQL is requested. Since you don't use it in the code you provided, there must be another database connection using MySQL.

share|improve this answer

I assume you might be running your program in IDE, so please add drivers jars in the classpath of project

share|improve this answer
what Class path path ..Please tell – user762357 May 20 '11 at 8:54
whats the database you are using with version numer – developer May 20 '11 at 8:59

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.