Witam
Mam problem z połączeniem się z bazą danych przeniesioną z localhosta na serwer, na localhoście wszystko działało ok, taki oto błąd wyskakuje przy próbie z połączeniem z serwerem:
Unable to connect to any hosts due to exception: java.net.SocketException: java.net.ConnectException: Connection refused: connect
** BEGIN NESTED EXCEPTION **
java.net.SocketException
MESSAGE: java.net.ConnectException: Connection refused: connect
STACKTRACE:
java.net.SocketException: java.net.ConnectException: Connection refused: connect
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:143)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:225)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:1805)
at com.mysql.jdbc.Connection.<init>(Connection.java:452)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:411)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at test.DBConnector.getCON(DBConnector.java:59)
at test.DBConnector.<init>(DBConnector.java:26)
at test.DBInterfejs.<init>(DBInterfejs.java:29)
at test.GlowneOkno.<init>(GlowneOkno.java:69)
at test.Odpalacz$1.run(Odpalacz.java:23)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
** END NESTED EXCEPTION **
Czy trzeba przerobić kod aby się łączył czy to beznaczenie?
Kod klasy odpowiedzialnej za połączenie z bazą;
public class DBConnector {
private static Connection CON;
private static Statement STM = null;
// private static Properties p;
public DBConnector() throws Exception {
getCON();
//getGuests();
}
public Connection getCON() {
Properties p = new Properties();
try {
p.load(new FileInputStream(file));
System.out.println("Properties file succesfully loaded");
} catch(IOException e) {
e.printStackTrace();
}
if (CON == null)
try {
Class.forName(p.getProperty("driver")).newInstance();
System.out.println("Driver succesfully loaded.");
} catch(Exception e) {
System.out.println(e.getMessage());
}
try {
CON = DriverManager.getConnection(p.getProperty("url"), p.getProperty("user"), p.getProperty("pass")); //linia 59
STM = CON.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
System.out.println("You are connected to the database!");
} catch(SQLException e) {
System.out.println(e.getMessage());
CON = null;
STM = null;
}
return CON;
}
@Override
protected void finalize() throws Throwable {
CON.close();
}
public Connection getConnection() {
return CON;
}
public Statement getStm() {
return STM;
}
}
plik .properties
driver=com.mysql.jdbc.Driver
url=jdbc:mysql://mysql2.xxx.pl:3306/db
user=user
pass=pass
Pozdrawiam
<font size="1" color="red">//edit koziolek: no nie jawnym hostem i hasłem proszę</span>