2

I have an application that uses java se and while coding it I installed mysql workbench on localhost, everything works fine. Now I have to distribute the jar files so that people can use it. but when I try accessing the database it says connection error. In the database path I replaced localhost with the ip of the computer the database is on. Could someone please help me out.

Thanks a lot

7
  • Could you post the full error message??? Commented Feb 19, 2012 at 4:41
  • 2
    you need to be able to ping or telnet the database server to make sure you can connect, have you tried to? Commented Feb 19, 2012 at 4:42
  • Check for database access permissions from remote hosts. Commented Feb 19, 2012 at 4:43
  • @Santosh Yeah i think thats the problem in the users window it says localhost ... how do i make it accessible from any ip? Commented Feb 19, 2012 at 4:48
  • @Qwe - excellent suggestion. Koool - you should be able to "telnet YOUR-HOST 3306" to verify the MySql port is open between the client and the remote MySql server. Commented Feb 19, 2012 at 4:52

2 Answers 2

1
  1. As you know, for JDBC in general, you need to specify the host in your connection string.

  2. As you also know, you typically specify the driver in Class.forName(), and the driver's .jar directory in your Java CLASSPATH.

  3. You're probably using the MySql/J connector - I believe that's all your client needs deployed along with your application.

  4. You also need to make sure the mySql port (default 3306) is open.

  5. Mysql "users" are defined and authorized on a per-host basis. You'll also need to make sure this is set up correctly in your "Users" mysql table.

  6. Be sure your application logs all available exception information. Please post any specific error messages here.

'Hope that helps

PS: The only relevance to "mysql workbench" is that your app happens to work when you run it locally, using mysql workbench, correct? If so, it probably isn't a good tag for this question...

Sign up to request clarification or add additional context in comments.

1 Comment

1. check 2. Class.forName("com.mysql.jdbc.Driver"); 3. done 4. done
1

Run the query on the DB as admin user.

GRANT ALL ON db1 TO 'jeffrey'@'%';

Assuming that db1 is your schema and jeffrey is the user you want to give access to.

3 Comments

so if i have this code in my app con = DriverManager.getConnection( "jdbc:mysql://ip/db1?"+"user=jeffrey&password="); it should work right?
from above comments I tried to ping and it says request failed what would be a solution to that??
You mean you cannot ping the machine which has database ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.