Click here to Skip to main content
15,912,400 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In this code i tried to connect my java program to MySQL database that stored on xtreemhost website but i cant.please help me to solve this





Java
         Connection con = null;
  String url = "jdbc:mysql://sql108.xtreemhost.com/";

  String db = " xth_10161434_pos";
  String driver = "com.mysql.jdbc.Driver";
  String user = "xth_10161434";
  String pass = "*****";
  
   
    try{
         
  Class.forName(driver);
  con =(Connection) DriverManager.getConnection(url+db, user, pass);
   Statement st = (Statement) con.createStatement();
   

  ResultSet rs=st.executeQuery("SELECT * FROM xth_10161434_pos.product LIMIT 0 TO 30;");
          
while(rs.next())
  {
System.out.println(rs.getString(2));
  }
    }
    catch(Exception e)
    {
    System.out.println(e);
  
    }



Showing an Exception:
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
Posted
Updated 27-Apr-16 10:24am
Comments
Herman<T>.Instance 8-Feb-12 9:36am    
are you allowed by any firewall to connect to a mysql server (portnumber xxxx)

You should use your own MySQL for testing. It is not a valid thing to use a foreign server for that. It might be possible that the provider of that service is blocking you due to false calls.

Check out XAMPP[^]. it's free, easy to use (you can simply switch it on and off) and will give you a complete webserver including MYSQL for your localhost.
 
Share this answer
 
Comments
vishnulalr 9-Feb-12 7:05am    
thanks for your advise but here i want to test my java app with an online database other than on localhost. xtreemhost.com is a free web hosting site
and i have an account vishnulalr.xtreemhost.com so i have a MySQL database there sql108.xtreemhost.com named _xth_10161434_pos now i think my question is clear
plS CHK THIS LINK

http://jdbcerrorinfo.blogspot.com/20...mysqljdbc.html
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900