| View previous topic :: View next topic |
| Author |
Message |
amz
Joined: 26 Apr 2012 Posts: 4
|
Posted: Thu Apr 26, 2012 7:44 am Post subject: Need Help: the .jar executable file doesn't connect to MySQL Database |
|
|
Hello, I have a problem with my java application. the application connects to a MySQL database. When run from netbeans, the program works fine and connects to the database normally. But when I open the .jar file in the "dist" folder, the program runs but doesn't connect to the database.
Note: the MySQL database is on another computer.
Thanks in advance for all help |
|
| Back to top |
|
 |
bolsover
Joined: 24 Jun 2010 Posts: 185
|
Posted: Thu Apr 26, 2012 10:36 am Post subject: |
|
|
Almost certainly a classpath issue...
Your .jar contains application classes but not the classes needed to connect to MySql which will be in one of the imported libraries.
I'm guessing that you are opening the .jar simply by double clicking rather than running it from a command prompt.
Open a command window and just type 'java' - you should get usage instrictions; you will need to use the -classpath option together with -jar and any other arguments.
db |
|
| Back to top |
|
 |
amz
Joined: 26 Apr 2012 Posts: 4
|
Posted: Sat Apr 28, 2012 5:34 am Post subject: |
|
|
that's true, i am opening it by double clicking it.
But I've already added the classpath to the environment variables.
Please explain more how to open it using commands |
|
| Back to top |
|
 |
lanshan75
Joined: 28 Apr 2012 Posts: 3 Location: florida
|
Posted: Sat Apr 28, 2012 6:44 am Post subject: |
|
|
Hello,everybody,I am just a new member of this forum,I want to make more friends here,I hope you can like me.
Cheap WOW Gold|Buy RS Gold|Diablo 3 Items |
|
| Back to top |
|
 |
bolsover
Joined: 24 Jun 2010 Posts: 185
|
Posted: Sat Apr 28, 2012 9:03 pm Post subject: |
|
|
Hi amz
what error do you actually get - can you post stacktrace?
my guess is that this is still a classpath issue... |
|
| Back to top |
|
 |
amz
Joined: 26 Apr 2012 Posts: 4
|
Posted: Mon Apr 30, 2012 6:28 am Post subject: |
|
|
when connecting to the database i used the try to catch the exception.
the exception message was: "No suitable driver found for jdbc:mysql://192.168.1.107/MyDB" |
|
| Back to top |
|
 |
bolsover
Joined: 24 Jun 2010 Posts: 185
|
Posted: Mon Apr 30, 2012 10:23 am Post subject: |
|
|
looks like a classpath issue...
have you added path the the mysqldriver .jar to classpath?? |
|
| Back to top |
|
 |
amz
Joined: 26 Apr 2012 Posts: 4
|
Posted: Mon Apr 30, 2012 11:45 am Post subject: |
|
|
This is the value of the CLASSPATH:
;C:\Program Files\Java\jdk1.6.0_17\jre\lib\ext\mysql-connector-java-5.1.8-bin.jar |
|
| Back to top |
|
 |
bolsover
Joined: 24 Jun 2010 Posts: 185
|
Posted: Mon Apr 30, 2012 4:24 pm Post subject: |
|
|
OK - so this looks like one of those Java gotchas - using java -classpath with -jar does not work... java ignores the -classpath
Instead, you need list ALL the .jar on the classpath and use a dot sparated path to your Main class:
java -classpath your-classes.jar;mysql-driver.jar dot.separated.path.to.MainClass |
|
| Back to top |
|
 |
|