java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver在java中不再起作用。如何解决这个问题? [英] java.lang.ClassNotFoundException: sun.jdbc.odbc.JdbcOdbcDriver doesn't work anymore in java. How to fix this?

查看:125
本文介绍了java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver在java中不再起作用。如何解决这个问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

两天前工作了。现在它没有。我100%确定编码是正确的。这是我用来连接数据库的方式。找不到我的问题的答案。请给我一个答案,因为我是java语言的初学者。 (使用jdk 7u72)

It worked two days ago. Now it doesn't. I'm 100% sure the coding is correct. This is the way I used to connect the database. Couldn't find an answer yet to my problem. Please give me an answer as i'm a beginner for java language. (Using jdk 7u72)

public void set()
{
    try
    {
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        String su=new String("jdbc:odbc:MOVIESURF"); //This is the database
        con=DriverManager.getConnection(su,"","");
        st=con.createStatement();
    }
    catch(Exception e2){System.out.println(e2);}
}

这是堆栈跟踪

 java.lang.ClassNotFoundException: sun.jdbc.odbc.JdbcOdbcDriver
         at java.net.URLClassLoader$1.run(Unknown Source)
         at java.net.URLClassLoader$1.run(Unknown Source)
         at java.security.AccessController.doPrivileged(Native Method)
         at java.net.URLClassLoader.findClass(Unknown Source)
         at java.lang.ClassLoader.loadClass(Unknown Source)
         at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
         at java.lang.ClassLoader.loadClass(Unknown Source)
         at java.lang.Class.forName0(Native Method)
         at java.lang.Class.forName(Unknown Source)
         at A.set(jptest7.java:410)
         at A.actionPerformed(jptest7.java:560)
         at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
         at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
         at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
         at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
         at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
         at java.awt.Component.processMouseEvent(Unknown Source)
         at javax.swing.JComponent.processMouseEvent(Unknown Source)
         at java.awt.Component.processEvent(Unknown Source)
         at java.awt.Container.processEvent(Unknown Source)
         at java.awt.Component.dispatchEventImpl(Unknown Source)
         at java.awt.Container.dispatchEventImpl(Unknown Source)
         at java.awt.Component.dispatchEvent(Unknown Source)
         at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
         at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
         at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
         at java.awt.Container.dispatchEventImpl(Unknown Source)
         at java.awt.Window.dispatchEventImpl(Unknown Source)
         at java.awt.Component.dispatchEvent(Unknown Source)
         at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
         at java.awt.EventQueue.access$400(Unknown Source)
         at java.awt.EventQueue$3.run(Unknown Source)
         at java.awt.EventQueue$3.run(Unknown Source)
         at java.security.AccessController.doPrivileged(Native Method)
         at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
         at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
         at java.awt.EventQueue$4.run(Unknown Source)
         at java.awt.EventQueue$4.run(Unknown Source)
         at java.security.AccessController.doPrivileged(Native Method)
         at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
         at java.awt.EventQueue.dispatchEvent(Unknown Source)
         at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
         at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.run(Unknown Source)

Connection failed select PASSWORD from USERS where USERNAME='ashane' ERROR:
 java.lang.NullPointerException


推荐答案

根据评论,您的系统现在在Java上运行8 JRE。 ODBC桥已从此以及所有未来版本中删除。您需要为要连接的数据库找到本机JDBC驱动程序,并将其放在类路径上。

Based on the comments, your system is now running on the Java 8 JRE. The ODBC Bridge has been removed from this, and all future versions. You need to find a native JDBC driver for the database you want to connect to, and put that on your classpath.

java -classpath "[/path/to/your/driver.jar];." [yourclassname]

或者,您可以显式使用JDK 7运行时,但我建议不要这样做。你已经发现了一个兼容性问题,最好解决它而不是尝试解决它。​​

Alternatively, you could explicitly use the JDK 7 runtime, but I'd recommend against this. You've uncovered a compatibility problem, and it's better to solve it than to try to work around it.

这篇关于java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver在java中不再起作用。如何解决这个问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆