0

Hello below is my jdbc code here I want to insert a record into remote machine, when Im using the same code with local Data Base server Im able to insert the record successfully. But When Im try with the remote machine it is throwing the following error.

And do please tell if the parameters that Im passing for creating connection are enough are need to add some thing else.

Errors:: When Im running the above code, getting below Exception

And also let me know if the connection details that Im passing in url are enough for making connection are need to add some thing else.

In order to connect to the remote sql server, only jdbc code is enough or should be developed as web application.

Someone Please tell me what I need to do, for resolving this problem!!

Thank you

 public class JdbcTestClass { public static void main(String [] args) throws SQLException { try { Class.forName("com.mysql.jdbc.Driver"); Connection con= DriverManager.getConnection("jdbc:mysql://120....:3306/example","root","root"); Statement st = con.createStatement(); st.executeUpdate("insert into test.student values(9966,'pradeep',93);"); System.out.println("Record Inserted Successfuly :: "); if(st != null) { st.close(); System.out.println("connection closed successfuly :: "+st); } if(con != null) { con.close(); } } catch (ClassNotFoundException e) { e.printStackTrace(); System.out.println("Error In 1st try :: "+e); } } } Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure Last packet sent to the server was 0 ms ago. 

1 Answer 1

1

please refer the answer from this URL :

Why I get this error 'Communications link failure The last packet sent...' when connecting to MySQL with Java (Netbeans)?

The problem was with mysql configuration file on the server /etc/mysql/my.cnf the line : bind-address should point to your server's IP like in this example bind-address = 192.168.1.5 and not bind-address = 127.0.0.1 to allow remote access. 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.