0

我的小程序有问题。它在小程序查看器中运行良好,但在Web browser它引发异常。

异常详情:

`SQLException: No suitable driver found for jdbc:mysql://s46.eatj.com:3307/cmentarz
Exception in thread "AWT-EventQueue-2" java.lang.NullPointerException
at JDBC.LogIn(JDBC.java:49)
at AdminPanelLogIn$1.actionPerformed(AdminPanelLogIn.java:64)
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.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(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)`

我已经使用 JARmaker 签署了我的 jar 文件。

我的getConnection方法代码:

public Connection getConnection() throws SQLException {

    try {
        Class.forName("com.mysql.jdbc.Driver");
    } catch (java.lang.ClassNotFoundException e) {
        System.err.print("ClassNotFoundException: ");
        System.err.println(e.getMessage());
    }

    try {
        con = DriverManager.getConnection(url, userid, password);
    } catch (SQLException ex) {
        System.err.println("SQLException: " + ex.getMessage());
    }
    return con;
}

Useridpassword并且url是正确的,因为它适用于小程序查看器。

static String url = "jdbc:mysql://s46.eatj.com:3307/cmentarz";

那么,可能是什么问题?

4

1 回答 1

0

确保MySQL在浏览器中运行时,该 jar 可用于您的小程序。你可以在你的applet(或object)标签中指定这个:

<applet code="org.package.MyApplet" width="800" height="600" archive="myappletjar.jar,mysql-connector-java-5.1.6-bin.jar">
</applet>

还要确保 jar 文件与您的 applet jar 文件存在于同一位置,以便可以下载。

于 2013-01-13T16:03:38.797 回答