database connectivity fails after creating jar file

柔情痞子 提交于 2019-12-02 18:52:00

问题


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

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.


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");

回答1:


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 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

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.



来源:https://stackoverflow.com/questions/28060231/database-connectivity-fails-after-creating-jar-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!