Berk Acikel
Berk Acikel

Reputation: 21

I cant connect SQL Server ClassNotFoundException

Hi guys i trying to connect SQL server with netbeans

public class SQLconnection {

    /**
     * @param args the command line arguments
     * @throws java.lang.ClassNotFoundException
     * @throws java.sql.SQLException
     */
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        String connectionURL = "jdbc:derby://localhost:1527;databaseName=Ornek;user=sa;password=123";
        Connection con  = DriverManager.getConnection(connectionURL);

        System.out.println("Connect");
    }

}

But İ have errors in Netbeans and i dont know how to pass

Exception in thread "main" java.lang.ClassNotFoundException: sun.jdbc.odbc.JdbcOdbcDriver at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:264) at sqlconnection.SQLconnection.main(SQLconnection.java:23)

Upvotes: 1

Views: 1016

Answers (2)

Rakesh Sinha
Rakesh Sinha

Reputation: 1

A java.lang.classnotfoundexception sun.jdbc.odbc.jdbcodbcdriver error occurs when you try to connect to a database from Java using JDBC and the JDBC ODBC bridge driver is not available in classpath.

You need to provide the driver jar in classpath.

Upvotes: -2

4dc0
4dc0

Reputation: 453

You need to find your driver .jar and add it to your classpath.

How to setup classpath in Netbeans?

It seems like the JDBC-ODBC bridge was removed in Java 8. The best thing I could find for you is a hack solution found in answer two of this link: Removal of JDBC ODBC bridge in java 8

As Oracle has stated here:

http://docs.oracle.com/javase/7/docs/technotes/guides/jdbc/bridge.html

"Oracle recommends that you use JDBC drivers provided by the vendor of your database instead of the JDBC-ODBC Bridge."

Upvotes: 1

Related Questions