NetBeans Forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
  

Need Help: the .jar executable file doesn't connect to MySQL Database

 
Post new topic   Reply to topic    NetBeans Forums -> NetBeans Users
View previous topic :: View next topic  
Author Message
amz



Joined: 26 Apr 2012
Posts: 4

PostPosted: Thu Apr 26, 2012 7:44 am    Post subject: Need Help: the .jar executable file doesn't connect to MySQL Database Reply with quote

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

PostPosted: Thu Apr 26, 2012 10:36 am    Post subject: Reply with quote

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

PostPosted: Sat Apr 28, 2012 5:34 am    Post subject: Reply with quote

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

PostPosted: Sat Apr 28, 2012 6:44 am    Post subject: Reply with quote

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

PostPosted: Sat Apr 28, 2012 9:03 pm    Post subject: Reply with quote

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

PostPosted: Mon Apr 30, 2012 6:28 am    Post subject: Reply with quote

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

PostPosted: Mon Apr 30, 2012 10:23 am    Post subject: Reply with quote

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

PostPosted: Mon Apr 30, 2012 11:45 am    Post subject: Reply with quote

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

PostPosted: Mon Apr 30, 2012 4:24 pm    Post subject: Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    NetBeans Forums -> NetBeans Users All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo