有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Windows Server 2003 JDBC驱动程序

我编写了一个简单的多人JAVA应用程序,可以使用JDBC驱动程序连接到MySQL。 最后我把它装进了箱子。jar文件。当我在本地机器MacOS上测试时,一切正常。(我不记得设置JDBC驱动程序的所有步骤,因为我写这个应用程序是在一年前)。此时,该应用程序连接到另一台服务器上的外部数据库(我没有更改,因为它没有问题)。如果是远程数据库的问题,这将是另一个错误

现在,当我需要在Windows Server 2003上进行生产时,我不断得到标准错误:

 java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
And I don't get it, because I think I've done the steps right:
0. Installed Java
1. downloaded this: http://dev.mysql.com/downloads/connector/j/
2. added it to the same folder where the app.jar is
3. wrote in cmd: set CLASSPATH =.;C:\Documents and Settings\Administrator\Desktop\tvplan_exchange\mysql-connector-java-5.1.28-bin.jar
4. tested the variable: echo %CLASSPATH% and it showed the same path
5. runned the app: java -jar app.jar
6. got the error:
    java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
    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 svagers.Db.connect(Db.java:21)
    at svagers.Server.main(Server.java:58)
    MYSQL ERRORcom.mysql.jdbc.Driver

嗯,对于那些认为使用这样的应用程序是一个安全错误的人来说,不用担心,这不是问题,我只是需要它来运行而不是考虑风险:

这就是环境: 操作系统:Windows Server 2003(标准版,Service Pack 2) Java:1.7.0_45(SE运行时环境


共 (1) 个答案

  1. # 1 楼答案

    我本来想说“用java -cp %CLASSPATH% -jar app.jar运行应用程序”,但后来我想起你不能两者兼有:你可以使用或者-jar或者-cp。请参见this答案