-1

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);
    }
  }
}

3 Answers3

2

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.

Buhake Sindi
  • 87,898
  • 29
  • 167
  • 228
  • that is not for mysql, its oracle drivers – developer May 20 '11 at 08:21
  • @Damodar, the `com.mysql.jdbc.Driver` pertains to the MySQL RDBMS and not Oracle Driver. – Buhake Sindi May 20 '11 at 08:23
  • 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 08: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 08:28
  • @The Elite Gentleman : cannt we connect oracle with jdbcodbc drivers? also , username and password ,mentioned there is default cerdentials of oracle database – developer May 20 '11 at 08:31
  • @Damodar, the ODBC driver exists. If you're persistent enough, you can set it up but I would **recommend** using the JDBC driver directly. – Buhake Sindi May 20 '11 at 08:38
  • @user762357, I can't edit your code **until** you specify how you have configured your oracle connections and `tnsnames.ora`. Follow the example I've provided. – Buhake Sindi May 20 '11 at 08:56
  • No problems. Hope this helps and don't forget to accept correct answers (by ticking the checkbox under the score) :) – Buhake Sindi May 20 '11 at 09:09
  • can u see thhis by team viewer? – user762357 May 20 '11 at 10:52
0

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

developer
  • 9,116
  • 29
  • 91
  • 150
0

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.

Osiris76
  • 1,234
  • 9
  • 5