Précédent   Forum des professionnels en informatique > Bases de données > PostgreSQL
PostgreSQL Forum PostgreSQL. Avant de poster -> F.A.Q PostGreSQL Tutoriels PostGreSQL
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 11/05/2005, 19h20   #1
Invité de passage
 
Inscription : mars 2005
Messages : 19
Détails du profil
Informations forums :
Inscription : mars 2005
Messages : 19
Points : 4
Points : 4
Par défaut 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 :
Code :
1
2
 
tcpip_socket = true
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 ???????????
tasdorjtador est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 11/05/2005, 20h31   #2
Membre émérite
 
Avatar de hpalpha
 
Inscription : mars 2002
Messages : 770
Détails du profil
Informations forums :
Inscription : mars 2002
Messages : 770
Points : 833
Points : 833
Ton serveur pg est il le meme que celui qui lance ton script ?
Sinon il faut que tu change
String URL = "jdbc:postgresql://localhost:5432/BD";
par
String URL = "jdbc:postgresql://192.168.1.55:5432/BD"; (si ton serveur est 192.168.1.55)
hpalpha est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 11/05/2005, 20h32   #3
Membre émérite
 
Avatar de hpalpha
 
Inscription : mars 2002
Messages : 770
Détails du profil
Informations forums :
Inscription : mars 2002
Messages : 770
Points : 833
Points : 833
y a aussi ton postgresql.conf :
il faut mettre
listen_addresses = '*'
hpalpha est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 11/05/2005, 20h48   #4
Invité de passage
 
Inscription : mars 2005
Messages : 19
Détails du profil
Informations forums :
Inscription : mars 2005
Messages : 19
Points : 4
Points : 4
le probleme c'est que je ne connais pas mon serveur je sais que j'utilise un serveur local mais comment connaitre son adresse...
je vais modifié le fichier postgresql.conf
tasdorjtador est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 11/05/2005, 21h18   #5
Invité de passage
 
Inscription : mars 2005
Messages : 19
Détails du profil
Informations forums :
Inscription : mars 2005
Messages : 19
Points : 4
Points : 4
hhhhhhhhooooooooo yyyyyyyyyeeeeeeaaaaaaaaaaahhhhhhhhhh

c'est bon j'ai trouvé le probleme , tellement ridicule , je crois que j'etais aveuglé par mon naturel pessimisme ( faut bien trouver des excuses)...

Ouvrez grand les oreilles je ne donnerai qu'une seule explication, tant pis pour ceux qui n'ecoutent pas , voila :
j'avais oublié de retirer le # devant tcpip_socket = true dans les fichiers postgresql.conf et postgresql.conf.sample.
pfff ça soulage

pendant qu'on y est est-ce qu'il est necessaire de modifier les 2 fichiers ou seul postgresql.conf peut etre modifié ??????
tasdorjtador est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 11/05/2005, 22h10   #6
Membre émérite
 
Avatar de hpalpha
 
Inscription : mars 2002
Messages : 770
Détails du profil
Informations forums :
Inscription : mars 2002
Messages : 770
Points : 833
Points : 833
seulement postgresql.conf, l'autre comme son nom l'indique c'est un exemple
hpalpha est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 11/05/2005, 22h11   #7
Membre émérite
 
Avatar de hpalpha
 
Inscription : mars 2002
Messages : 770
Détails du profil
Informations forums :
Inscription : mars 2002
Messages : 770
Points : 833
Points : 833
connexion locale : localhost ou 127.0.0.1

pour savoir ton ip sur le reseau (pour une connexion a distance) : ifconfig
hpalpha est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 21h53.


 
 
 
 
Partenaires

Hébergement Web