1

I successfully installed mySQL in my laptop. I created a database, table and inserted rows into it. I ran my program and got the desired output,i.e., the data from the database. Now, I created a jar file of my program with the driver. The jar is working fine in my PC. But when I ran the jar in another PC, I get the error:-
Excecom.mysql.exceptions.jdbc4.CommunicationsException : Communication Link Failure ... The driver has not received any packets from the server. Now this is obvious, as the database was not copied.
Now, WILL I HAVE TO INSTALL mySQL in each computer I run my .jar??. Then many other questions also arise that, what user shall I use in all the computers? and how do I create a database along with the jar.. Please solve my dilemma.

Deval Khandelwal
  • 3,458
  • 1
  • 27
  • 38
  • Why don't you create a properties file with the location of the mysql server in it. Your question is too broad as it is. Refine it, get an answer, then post a new question. – crush Jan 29 '14 at 15:19
  • whoops...looks like I do not know much about java. Lemme google that. – Deval Khandelwal Jan 29 '14 at 15:20
  • are you using DatabaseConnection.xml or similar like for Database connection? – java seeker Jan 29 '14 at 15:20
  • if you want to use your first pc as database server? – java seeker Jan 29 '14 at 15:22
  • there is a great answer to this question here http://stackoverflow.com/questions/2983248/com-mysql-jdbc-exceptions-jdbc4-communicationsexception-communications-link-fai – lakshman Jan 29 '14 at 15:25
  • Nope @javaseeker . I want that all the individual PC's as individual servers. – Deval Khandelwal Jan 29 '14 at 15:28
  • Hey @crush , I googled about the properties but could not figure out how to get the location of the mysql server in it? I mean that how would I know the location of the server in a PC unknown to me? – Deval Khandelwal Jan 29 '14 at 15:36
  • How is the PC unknown to you? What do you mean? – crush Jan 29 '14 at 15:38
  • @crush it can be any PC...even your PC – Deval Khandelwal Jan 29 '14 at 15:39
  • @crush my program should be able to run in any system which has java installed – Deval Khandelwal Jan 29 '14 at 15:40
  • Sure, but you still have to tell your program where the MySql database is located at. If the MySql database is supposed to be on the same computer as the computer running your program, then yes, you will need to install MySql server on that machine. – crush Jan 29 '14 at 15:41
  • @crush , Basically, I mean that I have got the username for the mySQL server for my PC(following the tutorial at http://www.vogella.com/tutorials/MySQLJava/article.html#jdbc ). But I want to distribute the jar file. Now how the heck would I connect to server in another PC whose username is unknown to me? – Deval Khandelwal Jan 29 '14 at 15:43
  • @crush , Then how would I do that...means would I just distribute the mysql 213 MB while distributing my jar?? and furthermore...which USERNAME to use?? – Deval Khandelwal Jan 29 '14 at 15:44
  • As long as it doesn't violate MySql's licensing, sure. You should setup all these settings in a Properties file, assume default settings, but allow the user of your program to configure them in the event that they setup their MySql server differently...this question is way to broad. I'm done here. – crush Jan 29 '14 at 15:45

2 Answers2

1

I think you should be more clear in what you are asking, but to answer your questions :

  • WILL I HAVE TO INSTALL mySQL in each computer I run my .jar??.

    No

  • what user shall I use in all the computers?

    This depends on the level of security you require, but if configured to access from any host you can use the same user/pass on all the computers.

migueldiab
  • 82
  • 1
  • 4
1

Well mySQL is not appropriate for programs that you need to distribute. SQLite is best file-based database and I am happily shifting to it. Thanks SO for the guidance.

Deval Khandelwal
  • 3,458
  • 1
  • 27
  • 38