创建jar文件后数据库连接失败 [英] database connectivity fails after creating jar file

查看:121
本文介绍了创建jar文件后数据库连接失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用notepad创建了一个项目。并且在cmd中使用mysql服务器数据库运行良好。

I created a project with notepad.And running well in cmd with mysql server database.

但是在创建了同一项目的jar文件后,jar文件无法使用连接到服务器数据库。所以不知道接下来该做什么?即使其他系统(仅安装了java而不是mysql)在从cmd或jar文件运行后也无法连接到服务器数据库。

But after creating a jar file of same project then jar file is not able to connect to the server database.so don't know what to do next? Even though other systems (only installed java not mysql) are unable to connect to the server database after running from either cmd or jar file.

是否每个系统都必须在其他系统上安装java和mysql才能运行?如何克服这样的问题。我想将它分发给用户但我无法做到这一点...
code ---> Class.forName(com.mysql.jdbc.Driver);

Is it necessary for every systems to have java and mysql installed on other systems to run? How to overcome from such problem. I want to distribute it to the users but i am unable to do that... code--->Class.forName("com.mysql.jdbc.Driver");

Connection conn=DriverManager.getConnection("jdbc:mysql://serverhostname:3306/databasename"‌​,"username","password");


推荐答案

以下是解决方案,

以下是manifest.txt文件的内容

Here is the solution,
following are the content of manifest.txt file

Main-Class: filename
Class-Path: . mysql-connector-java-5.1.33-bin.jar

mysql-connector-java-5.1。 33-bin.jar连接器必须位于同一目录中,以便jar文件包含它。
这个连接器可以很容易地下载,也可以在程序文件下的mysql文件夹中找到。
之后从cmd,必须执行命令

mysql-connector-java-5.1.33-bin.jar connector must be in the same directory so that the jar file include it.
This connector can be easily downloaded or can be found in mysql folder under program files
After that from the cmd, command must be executed

jar -cvfm jarfilename.jar manifest.txt *.class

将根据您的类文件和清单创建一个新的jar文件,然后可以使用double轻松运行单击,服务器将与cmd模式响应相同。

A new jar file will be created based upon your class file and manifest,then it can be easily runnable with double click and the server will respond same as that of cmd mode.

这篇关于创建jar文件后数据库连接失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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