0

I have a code which runs fine on the machine, where i have installed the database.

I am trying to run this code from other machine, which connects to the machine where MySQL is installed and tries to update data. However this code is not working from other machine. i am trying to connect as follows.

ds = new BasicDataSource();
ds.setDriverClassName("com.mysql.jdbc.Driver");
ds.setUrl("jdbc:mysql://192.168.0.104:3306/sd_mmm_data");
ds.setUsername("<UserName>");
ds.setPassword("<PassCode>");
ds.setMaxIdle(1);
ds.setMaxWaitMillis(40000);

I have replaced the localhost with the corresponding IP. However when i run the code, i always get the error table not found.

I have created a new user which can connect from other machines and the user has all of the required privileges. i have tried connecting from cmd prompt on client system and the connection works as expected queries run as expected. i tried connecting from mysql WorkBench and the connection works from client system. but the connection doesn't work from Java code. What am i missing?

I have added an entry in client system hosts file as follows ServerName And i tried using the ServerName in place of IP address in java code. Even this didn't work.

kris123456
  • 501
  • 1
  • 5
  • 15
  • You should put the complete java code I think. – Masked Man Aug 09 '16 at 10:18
  • what is the name of the table ? – Rafik BELDI Aug 09 '16 at 10:21
  • When you recieve a "Table not found" Error there isn't a problem with connecting to the server – Nico T Aug 09 '16 at 10:22
  • 1
    Did you [try this](http://stackoverflow.com/questions/14779104/how-to-allow-remote-connection-to-mysql) – Sanjeev Aug 09 '16 at 10:23
  • Guys.. all of the required code has been pasted above. the only thing that's missing is getting the connection and querying the data base which are obvious, and the connection isn't working. The table name doesn't matter as the table exists on server and i can query the table from client machine command prompt. – kris123456 Aug 09 '16 at 10:23
  • Can you put exact exception that you are getting ? – DevG Aug 09 '16 at 10:45

2 Answers2

1

I think you have to use grant the remote user which enables access for remote user.

GRANT ALL PRIVILEGES ON . TO 'USERNAME'@'1.2.3.4' IDENTIFIED BY 'PASSWORD' WITH GRANT OPTION;

Sudip
  • 92
  • 7
  • The user name and password are working from Client Machine. i have tested the connection from command prompt and from WorkBench on Client Machine. The connection is working and am able to fetch the data too. The connection is not working only from Java code. – kris123456 Aug 09 '16 at 10:44
0

Created new set of users. Flushed privileges but it didn't work. Then went on with shutting down the database and tried restarting it. Even it didn't work. But tried fiddling with settings and tried creating new users and tried connecting, which finally worked. Don't exactly remember why it worked as i touched multiple network settings.

kris123456
  • 501
  • 1
  • 5
  • 15