erreur lors de la connexion à une base postgresql
bonjour,
j'ai une connexion à ma base postgresql qui fonctionnait bien avant que je ne veuille externaliser les paramètres de connexion dans un fichier de propriétés dans le répertoire ressource et lu avec le class loader
quand j'utilise le code
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
| private GPConnexionAnnuaire() {
Properties prop = org.genealogie.genientique.commun.Commun
.getProprietes();
try {
// prop.setProperty("utilisateur", "peche");
// prop.setProperty("motdepasse", "redras44");
Class.forName("org.postgresql.Driver");
FileOutputStream fos = new FileOutputStream("D:/Users/Gilbert/java/workspace/GeniEnTique/GenientiqueApplication/resource/gilbert.properties");
// prop.store(fos, "");
fos.close();
String motdepasseI = prop.getProperty("motdepasse");
String utilisateurI = prop.getProperty("utilisateur");
String url = "jdbc:postgresql://" + prop.getProperty("serveur")
+ ":" + prop.getProperty("port") + "/"
+ prop.getProperty("base")
// + "?user=" + utilisateurI
// + "&password=" + motdepasseI
;
con = DriverManager.getConnection(url,utilisateurI, motdepasseI);
} catch (SQLException e) {
// TODO: handle exception
exception = e;
e.printStackTrace();
// }
}catch (ClassNotFoundException e) {
// TODO: handle exception
exception = new SQLException(e);
e.printStackTrace();
} catch (IOException e) {
// TODO: handle exception
exception = new SQLException(e);
e.printStackTrace();
}
} |
j'obtiens l'erreur Séquence UTF-8 illégale: l'octet 2 de la séquence d'octet 3 n'est pas 10xxxxxx: 99
alors que si j'utilise
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 45 46
| private GPConnexionAnnuaire() {
Properties prop = org.genealogie.genientique.commun.Commun
.getProprietes();
// PGSimpleDataSource pgSimpleDataSource = new PGSimpleDataSource();
// pgSimpleDataSource.setServerName("localhost");
// pgSimpleDataSource.setPortNumber(5432);
// pgSimpleDataSource.setUser("peche");
// pgSimpleDataSource.setDatabaseName("annuaire");
// pgSimpleDataSource.setPassword("redras44");
//
try {
// con = pgSimpleDataSource.getConnection();
prop.setProperty("utilisateur", "peche");
prop.setProperty("motdepasse", "redras44");
Class.forName("org.postgresql.Driver");
FileOutputStream fos = new FileOutputStream("D:/Users/Gilbert/java/workspace/GeniEnTique/GenientiqueApplication/resource/gilbert.properties");
prop.store(fos, "");
fos.close();
String motdepasseI = prop.getProperty("motdepasse");
String utilisateurI = prop.getProperty("utilisateur");
String url = "jdbc:postgresql://" + prop.getProperty("serveur")
+ ":" + prop.getProperty("port") + "/"
+ prop.getProperty("base")
// + "?user=" + utilisateurI
// + "&password=" + motdepasseI
;
con = DriverManager.getConnection(url,utilisateurI, motdepasseI);
} catch (SQLException e) {
// TODO: handle exception
exception = e;
e.printStackTrace();
// }
}catch (ClassNotFoundException e) {
// TODO: handle exception
exception = new SQLException(e);
e.printStackTrace();
} catch (IOException e) {
// TODO: handle exception
exception = new SQLException(e);
e.printStackTrace();
}
} |
c'est à dire en forçant le login dans la méthode,la connexion se s'effectue correctement
la configuration de test
windows 10
eclipse helios
java 1.6
base postgesql 9.5
merci pour réponses
Cordialement,
Gilbert Pêche