bonjour,
bon j'ai un petit problème concernant la connexion de ma bdd postgresql, donc la connexion ce fait très bien sauf que laur de l’exécution ma bdd ce connecte deux fois alors que j'ai un seul code de connexion donc si vous pouvez m'aidez !!
merci
bon au debut ya ma socket qui ce connecte elle marche bien !!
ServerSocket serverSocket=null;
int port = 8083;
try {
serverSocket = new ServerSocket(port);
System.out.println("Le Serveur est pret, sur le port " + serverSocket.getLocalPort());
}
catch (IOException e) {
System.err.println("Exception: impossible de creer ServerSocket: " + e);
System.exit(1);
}
while (true) {
try {
System.out.println("en attente d'une nouvelle connection client...");
System.out.flush();
Socket clientSocket = serverSocket.accept();
System.out.println("nouvelle connection etablie");
System.out.flush();
Coo connection = new Coo(clientSocket);
connection.start();
}
catch (IOException e) {
System.err.println("Exception lancee par ServerSocket.accept: " + e);
System.exit(1);
}
catch (CooException e) {
System.err.println(
"Exception lancee pendant la construction de la connection: " + e);
System.exit(1);
}
}
}
}
@SuppressWarnings("serial")
class CooException extends Exception {
Exception e;
CooException(Exception e) { this.e = e; }
CooException(String msg) { super(msg); e=this; }
}
class Coo extends Thread {
private Socket clientSocket;
private PrintWriter os;
private BufferedReader is;
Coo(Socket clientSocket)
throws CooException {
this.clientSocket = clientSocket;
try {
os = new PrintWriter(clientSocket.getOutputStream());
is = new
BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
}
catch (IOException e) {
System.err.println("Exception en ouvrant les streams du client: " + e);
throw new CooException(e);
}
}
et la c'est la connexion de ma bdd !! et ya suite du code j'ai copier le tous !!
public void run() {
String ligneClient;
System.out.println("attente du message d'ouverture du client...\n");
System.out.flush();
try {
ligneClient = is.readLine();
int l=ligneClient.length();
Class.forName("org.postgresql.Driver");
System.out.println("DRIVER OK ! \n");
String url = "jdbc:postgresql://localhost:5432/Kerberos";
String user = "postgres";
String passwd = "yougho";
Connection conn = DriverManager.getConnection(url, user, passwd);
System.out.println("Connection effective !\n");
Statement stat = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
String quer= "SELECT * FROM serveur WHERE nom_serv = 'kerberos'";
ResultSet res = stat.executeQuery(quer);
res.next();
String Ks=res.getString("cle");
voila
problem connection bdd postgresql
× 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.