org.postgresql.util.PSQLException: Connection to localhost:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
import java.sql.Connection;
import java.sql.DriverManager;
public class Database {
private Connection connection;
// private final String host = "ssprojectinstance.csv2nbvvgbcb.us-east-2.rds.amazonaws.com" // For Amazon Postgresql
private final String host = "192.168.0.21";
private final String database = "test";
private final int port = 5432;
private final String user = "postgres";
private final String pass = "pass";
private String url = "jdbc:postgresql://%s:%d/%s";
private boolean status;
public Database() {
this.url = String.format(this.url, this.host, this.port, this.database);
connect();
//this.disconnect();
System.out.println("connection status:" + status);
}
private void connect() {
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
try {
Class.forName("org.postgresql.Driver");
connection = DriverManager.getConnection(url, user, pass);
status = true;
System.out.println("connected:" + status);
} catch (Exception e) {
status = false;
System.out.print(e.getMessage());
e.printStackTrace();
}
}
});
thread.start();
try {
thread.join();
} catch (Exception e) {
e.printStackTrace();
this.status = false;
}
}
public Connection getExtraConnection(){
Connection c = null;
try {
Class.forName("org.postgresql.Driver");
c = DriverManager.getConnection(url, user, pass);
} catch (Exception e) {
e.printStackTrace();
}
return c;
}
}
qui ne fonctionne pas non plus.
Caused by: java.lang.ClassNotFoundException: Didn't find class "java.lang.management.ManagementFactory" on path: DexPathList[[zip file "/data/app/~~jjxh5PFUiZMDogrDDFgwqw==/com.example.toolpss-RvMuPOZeIwf8zttg7YuZOg==/base.apk"],nativeLibraryDirectories=[/data/app/~~jjxh5PFUiZMDogrDDFgwqw==/com.example.toolpss-RvMuPOZeIwf8zttg7YuZOg==/lib/x86, /system/lib, /system_ext/lib]]
Je me dis que je me trompe quelque part mais je trouve pas
Si vous avez des idée
Postgresql connection impossible
× Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
× Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.