2

I'm learning java, our teacher (using jdk 7, netbeans) showed us the way to connect to Microsoft SQL Server 2008. Now I am doing the same, but I have an error:

java.lang.ClassNotFoundException: jdbc.odbc.JdbcOdbcDriver

I googled it for straight 4 hours and I finally found the issue: I'm using jdk8, now people are saying that jdk8 removed JDBC driver and you have to download it from this site:

http://www.microsoft.com/en-us/download/details.aspx?displaylang=en&id=11774

I did this, but I don't know how to run it. What to do, I'm completely blank. Could someone please tell me how to connect to the database.

Even this is perfectly done, no issues over here: enter image description here

The simple code just to test the connection:

package sqlexamples;
import java.sql.*;
public class Example {
 public static void main(String[] args) {
 try{
 Class.forName("jdbc.odbc.JdbcOdbcDriver");
 System.out.println("Driver Successfully Loaded!");
 Connection connect = DriverManager.getConnection("jdbc:odbc:library;user=maisam;password=db123");
 System.out.println("Connected to Database!");
 PreparedStatement state = connect.prepareStatement("Select * from mytable");
 System.out.println("Query Executed Successfully!");
 connect.close();
 System.out.println("Database Closed!");
 }
 catch(ClassNotFoundException ex){
 System.out.println("Error: Driver Class not found.");
 ex.printStackTrace();
 }
 catch(SQLException sqlex){
 System.out.println("Error: SQL Error");
 sqlex.printStackTrace();
 }
 }
}

Error: Driver Class not found. java.lang.ClassNotFoundException: jdbc.odbc.JdbcOdbcDriver at java.net.URLClassLoader1ドル.run(URLClassLoader.java:372) at java.net.URLClassLoader1ドル.run(URLClassLoader.java:361) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:360) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:260) at sqlexamples.Example.main(Example.java:11) BUILD SUCCESSFUL (total time: 0 seconds)

EDIT: I'm just thinking to switch back to JDK7 until my project of [Library System Management] is done.

Mark Rotteveel
110k241 gold badges160 silver badges233 bronze badges
asked Jan 14, 2015 at 20:39
6
  • stackoverflow.com/search?q=%5Bjava-8%5D+odbc Commented Jan 14, 2015 at 20:41
  • @Holger sir, i searched these long ago, they're for Microsoft Access, even i tried to find the logic and changes, cant get it. Commented Jan 14, 2015 at 20:44
  • @Holger ok sir, i got it, but why they made this thing so complicated , it was good in previous versions Commented Jan 14, 2015 at 20:50
  • 1
    blogs.oracle.com/Lance/entry/removal_of_the_jdbc_odbc Commented Jan 14, 2015 at 20:52
  • 1
    If you already have downloaded and installed the "Microsoft JDBC Drivers 4.1 and 4.0 for SQL Server", you have to remove the line Class.forName("jdbc.odbc.JdbcOdbcDriver");, then change the connection String from something beginning with "jdbc:odbc:..." to something as described in this instructions Commented Jan 14, 2015 at 21:00

1 Answer 1

3

people are saying that jdk8 removed jdbc driver

That is not true. It was the JDBC-ODBC Bridge that was removed from Java 8. Therefore you cannot use an ODBC driver to connect to SQL Server from Java 8. Instead, you need to use a JDBC driver like this one:

Microsoft JDBC Driver for SQL Server

(The download link in your question is also for Microsoft's JDBC driver for SQL Server. Your problem is that the instructions you are following are for ODBC, not JDBC. Use the instructions for the JDBC driver instead.)

answered Jan 14, 2015 at 20:51
Sign up to request clarification or add additional context in comments.

1 Comment

sir i've downloaded it, 4.1 but i dont know how to connect it , i am using netbeans

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.