[Jdbc et postgresql ] connexion impossible a la base
salut,
OS : linux
j'ai un petit souci (qui dure pourtant depuis longtemps) pour me connecter a une
BD a partir d'un scripte java.
Je pense que le script n'est pas la source du probleme ce serai plutot la config de postgresql, enfin ça c'est a vous d'en juger.
voila l'erreur renvoyée :
Citation:
*** Driver OK ***
-> Connexion a la base...
ERREUR: Connexion impossible.
Message: Connection refused. Check that the hostname and port is correct, and that the postmaster is running with the -i flag, which enables TCP/IP networking.
Etat: null
Code Erreur: 0
je vous livre mon code si ça peut eclairer votre reflexion :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
import javax.sql.*;
import java.io.FileReader;
import java.sql.*;
public class connection
{
public static void main (String args[])
throws Exception
{
String URL = "jdbc:postgresql://localhost:5432/BD";
String driver ="org.postgresql.Driver";
Connection con = null;
try {
Class.forName(driver); //.newInstance();
System.out.println("*** Driver OK ***");
}
catch (Exception e) {
System.out.println("ERREUR: Chargement impossible.\n" + e);
}
System.out.println("-> Connexion a la base...");
try {
con = DriverManager.getConnection(URL,"marceau","");
//Statement stmt = con.createStatement();
System.out.println("*** Connexion OK ***");
}
catch(SQLException e) {
System.out.println("ERREUR: Connexion impossible.");
while (e != null) {
System.out.println("Message: " + e.getMessage());
System.out.println("Etat: " + e.getSQLState());
System.out.println("Code Erreur: " + e.getErrorCode() + "\n");
e = e.getNextException();
}
}
finally {
try { con.close();} catch(Exception e) {}
}
}
} |
je ne sais plus quoi faire , j'ai modifié postgresql.conf et postgresql.conf.sample avec :
et aussi pg_hba.conf et pg_hba.conf.sample avec :
Code:
1 2 3 4
|
# TYPE DATABASE USER IP-ADDRESS IP-MASK METHOD
local all all <empty> <empty> trust
host all all 127.0.0.1 255.255.255.255 trust |
any idear ???????????