I've seen few threads about this topic but I still can't figure out what's wrong. Following is the code:
import java.sql.*;
public class SQL
{
public static void main(String[] args)
{
Connection conn = null;
String url = "jdbc:mysql://mysql1.oyo.co.il:3306/";
String dbName = "sdarot2_winner";
String driver = "com.mysql.jdbc.Driver";
String userName = "";
String password = "";
String table = "LEADER_CAM_PRODUCTS";
try {
Class.forName(driver).newInstance();
conn = DriverManager.getConnection(url+dbName,userName,password);
System.out.println("Connected to the database");
conn.close();
System.out.println("Disconnected from database");
}catch (Exception e) {
System.out.println(e);
}
}
}
And here is the error I get:
com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying > > exception:
** BEGIN NESTED EXCEPTION **
java.net.ConnectException MESSAGE: Connection timed out: connect
STACKTRACE:
java.net.ConnectException: Connection timed out: connect at java.net.PlainSocketImpl.socketConnect(Native Method) at java.net.PlainSocketImpl.doConnect(Unknown Source) at java.net.PlainSocketImpl.connectToAddress(Unknown Source) at java.net.PlainSocketImpl.connect(Unknown Source) at java.net.SocksSocketImpl.connect(Unknown Source) at java.net.Socket.connect(Unknown Source) at java.net.Socket.connect(Unknown Source) at java.net.Socket.(Unknown Source) at java.net.Socket.(Unknown Source) at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:256) at com.mysql.jdbc.MysqlIO.(MysqlIO.java:271) at com.mysql.jdbc.Connection.createNewIO(Connection.java:2744) at com.mysql.jdbc.Connection.(Connection.java:1553) at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285) at java.sql.DriverManager.getConnection(Unknown Source) at java.sql.DriverManager.getConnection(Unknown Source) at SQL.main(SQL.java:17)
** END NESTED EXCEPTION **
Last packet sent to the server was 1 ms ago.
Here is few things I found around:
- The I.P/domain or port is incorrect
- The I.P/domain or port (i.e service) is down
- The I.P/domain is taking longer than your default timeout to respond
- You have a firewall that is blocking requests or responses on whatever port you are using
- You have a firewall that is blocking requests to that particular host
- Your internet access is down
a) it is correct. b) it's not down since I got a website that is working right now with that database. c) how can I check that?I don't think that it's the problem since as I said I got a running website on this database. d) now way because the same reason I mentioned above. e) samem as d
So what I'm doing wrong?how come a php code can work with sql but java gives me errors? Thank you.