启动时的 MySQL ExceptionInInitializerError Java JDBC [英] MySQL ExceptionInInitializerError Java JDBC on Startup

查看:24
本文介绍了启动时的 MySQL ExceptionInInitializerError Java JDBC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个使用 SQL 数据库的简单小程序.
当我在 Netbeans 上本地使用这个小程序时,它运行良好,没有问题,但是当我将它部署到 Web 时,我收到了一个奇怪的错误.
我在本地使用 Java 1.6,我部署的服务器正在运行 Java 1.6
我使用的是 J2BC 5.1.22.
这是我得到的错误:

I am making a simple applet that uses an SQL Database.
When I use this applet locally on Netbeans it runs fine without a problem, yet when I deploy it to the Web I am getting a weird error.
I am using Java 1.6 locally, and the server I deploy on is running Java 1.6
I am using J2BC 5.1.22.
This is the error I get:

java.lang.ExceptionInInitializerError
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:315)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at FinalProject.DBConnect.<init>(DBConnect.java:29)
at FinalProject.TriviaApplet.init(TriviaApplet.java:61)
at com.sun.deploy.uitoolkit.impl.awt.AWTAppletAdapter.init(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
    Caused by: java.security.AccessControlException: access denied
    ("java.util.PropertyPermission" "file.encoding" "read")
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPropertyAccess(Unknown Source)
at java.lang.System.getProperty(Unknown Source)
at com.mysql.jdbc.StringUtils.<clinit>(StringUtils.java:70)

我用来初始化驱动程序的代码是:

The code I use to initialize the driver is:

        Class.forName("com.mysql.jdbc.Driver");
        connection = DriverManager.getConnection(connectionURL, "db", "pw");

有没有人知道为什么会发生这种情况?

Does any one have any insight as to why this is occuring?

另外,我的 Applet 从另一个类中获取所有信息.^ 以上来自 DBConnect 类.这个类的一个实例被创建,这个类完成所有的 DB 工作.这是作为小程序完成的要求.我已经对我的 jar 和包含 JDBC 驱动程序的 lib jar 进行了签名.

To add, my Applet gets all the information from another class. ^ The above is from DBConnect Class. An instance of this class is created, and this class does all the DB work. It was a requirement for this to be done as an applet. I have signed both my jar, and the lib jar containing the JDBC driver.

推荐答案

是由于网络安全问题.您的 JDBC 驱动程序是如何部署到客户端的?你给他们足够的许可吗?其实就是在applet中使用JDBC在valueless中访问数据库.

it is due to the web security problem. how your JDBC driver is deployed to the client? do you give them enought permission? in fact, using JDBC in applet to visit the database in value-less.

  1. 它要求所有客户端都必须安装 JRE 和 CLASSPATH 中的 JDBC 驱动程序,您可以尝试将 JDBC 驱动程序与您的小程序打包在同一个 JAR 中.

  1. it requires all the client must have JRE installed and JDBC driver in CLASSPATH, you can try to package the JDBC driver with your applet in a same JAR.

需要通过在每个本地 JRE 中授予套接字连接来修改策略.

it need the policy modification by grant the socket connection in every local JRE.

permission java.net.SocketPermission "10.6.1.16:1521", "connect, resolve";

这使得这个解决方案几乎毫无用处..

that make this solution nearly useless..

这篇关于启动时的 MySQL ExceptionInInitializerError Java JDBC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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