wood burning stoves 2.0*
The moose likes JDBC and the fly likes JDBC connection works in jar file on my computer but not anyone else's Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "JDBC connection works in jar file on my computer but not anyone else Watch "JDBC connection works in jar file on my computer but not anyone else New topic
Author

JDBC connection works in jar file on my computer but not anyone else's

Zachary Bohley
Greenhorn

Joined: Aug 08, 2012
Posts: 3
Not sure if this is the right place to post this, so I apologize if it should be somewhere else.

I recently created a program that allows a user to add "customers" into a database. I am using MySQL to manage the database and Netbeans IDE to write the code. I am able to compile the jar file and run it on my computer to add records to this database, but when I move it to another computer, everything seems to work normally. When I look at the database records however, the customer has not been added and it appears as if MySQL has completely ignored my command. I am not sure if this is a MySQL problem or if there is a problem with my JAR file that would cause it to not function properly on other computers.

Thank you for your time.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18710
    
    8

It probably isn't a problem with MySQL. And it probably isn't a problem with your JAR file.

However the problem at present is that you can't tell what the problem is. Most likely that's because you have your program written to ignore exceptions. Do you have catch-blocks which look like this?



If so, fix them so they display the exception (and its stack trace) in some place where you can see them. At any rate your first task is to find out what exceptions are being thrown.
William P O'Sullivan
Ranch Hand

Joined: Mar 28, 2012
Posts: 859

Do these other computers have the required mysql jars, correct connection strings,

*AND* are they allowed to. There could be some firewall, networking issues also.

If you are not getting any descriptive errors, then Paul may be correct.

WP
Zachary Bohley
Greenhorn

Joined: Aug 08, 2012
Posts: 3
Paul Clapham wrote:It probably isn't a problem with MySQL. And it probably isn't a problem with your JAR file.

However the problem at present is that you can't tell what the problem is. Most likely that's because you have your program written to ignore exceptions. Do you have catch-blocks which look like this?



If so, fix them so they display the exception (and its stack trace) in some place where you can see them. At any rate your first task is to find out what exceptions are being thrown.


Paul, I think you are right about my code ignoring exceptions. Here is an example of the code that I am trying to run:



I'm not sure how I can show exceptions on a computer that does not have an IDE. I'm admittedly a bit new at running jar files on computers that I am not programming on. Do you have any ideas?


William P O'Sullivan wrote:
Do these other computers have the required mysql jars, correct connection strings,

*AND* are they allowed to. There could be some firewall, networking issues also.

If you are not getting any descriptive errors, then Paul may be correct.

WP


I disabled the Windows firewall on the server and our workstations, so I think I can rule that out. As far as the mysql jars and connection strings... I think it's correct. I included the MySQL drivers and libraries when I compiled.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18710
    
    8

Zachary Bohley wrote:I'm not sure how I can show exceptions on a computer that does not have an IDE. I'm admittedly a bit new at running jar files on computers that I am not programming on. Do you have any ideas?


Sure. Pretend you don't have the IDE and run the program in exactly the same way you plan to run it on those other computers.

I included the MySQL drivers and libraries when I compiled.


But that wasn't the question. The question was whether they were sent to the other computers.

It seems that you're a typical victim of IDEs. New programmers are talked into using an IDE because it makes it easier to write programs, but then they don't learn what it takes to actually run Java code. So like I suggested, put the IDE aside and try to run your program from the command line in your own computer.
Zachary Bohley
Greenhorn

Joined: Aug 08, 2012
Posts: 3
Looks like the problem was that my MySQL drivers weren't being included in the jar file.. It has been solved now. Thank you for your help.
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30789
    
157

Great! Thanks for posting the solution!


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
Consider Paul's rocket mass heater.
 
subject: JDBC connection works in jar file on my computer but not anyone else's