Bonjour,
je n'arrive pas à établir plusieurs connexions successives à différentes bases de données Oracle.
Lorsque j'utilise ma classe pour une seule connexion tout va bien, mais dès que j'utilise cette classe pour créer plusieurs connexions successives dans une boucle, j'ai l'erreur suivante :
Voici ma classe Connexion :java.sql.SQLException: Exception d'E/S: The Network Adapter could not establish the connection
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:334)
at oracle.jdbc.ttc7.TTC7Protocol.handleIOException(TTC7Protocol.java:3668)
at oracle.jdbc.ttc7.TTC7Protocol.logon(TTC7Protocol.java:353)
at oracle.jdbc.driver.OracleConnection.<init>(OracleConnection.java:371)
at oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.java:551)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:351)
at java.sql.DriverManager.getConnection(DriverManager.java:525)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at test.Connexion.<init>(Connexion.java:35)
Code java : Sélectionner tout - Visualiser dans une fenêtre à part
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
47
48
49
50 import java.io.FileInputStream; import java.io.IOException; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.util.Properties; public class Connexion { private String url = "jdbc:oracle:thin:@"; private Connection connect; public Connexion(String envi, String compte) { String bdd = null; String user = null; String passwd = null; this.connect = null; try { Properties prop = new Properties(); FileInputStream in = new FileInputStream("param.properties"); prop.load(in); in.close(); bdd = prop.getProperty(envi + ".BDD") + ":1521"; user = prop.getProperty(compte+".ORACLE.login"); passwd = prop.getProperty(compte+".ORACLE.mdp"); } catch (IOException e) { } try { // Register the Oracle JDBC driver DriverManager.registerDriver(new oracle.jdbc.OracleDriver()); // connecting to the DB this.connect = DriverManager.getConnection(url + bdd + ":SCHEMA", user, passwd); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public Connection getConnect() { return connect; } public void setConnect(Connection connect) { this.connect = connect; } }
Et les deux méthodes que j'utilise pour les connexions multiples :
Code java : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 private void recapVersion() throws IOException { String[] str=null; Properties prop = new Properties(); FileInputStream in = new FileInputStream("param.properties"); prop.load(in); in.close(); int nbenvi = Integer.parseInt((String) prop.getProperty("envi")); for(int i=0; i<nbenvi; i++) { str[i] = recupereVersion("Q"+i); } for(int j=0;j<str.length;j++) { System.out.println(str[j]); } }
et
Je ne comprends vraiment pas ces erreurs.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
47
48
49
50
51
52
53
54 private String recupereVersion(String envi) { Statement statement = null; ResultSet resultSet = null; String str=null; Connexion connexion = new Connexion(envi,"COMPTE"); Properties prop = new Properties(); FileInputStream in; try { in = new FileInputStream("opal.properties"); prop.load(in); in.close(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { statement = connexion.getConnect().createStatement(); statement .execute("select * from (select * from version t order by t.dateinstall desc) where rownum <9"); resultSet = statement.getResultSet(); while (resultSet.next()) { str+=(resultSet.getString("VERSION") + " " + resultSet.getDate("DATEINSTALL").toString()); } } catch (SQLException sqle) { } finally { try { if (resultSet != null) { resultSet.close(); } } catch (Exception e) { } try { if (statement != null) { statement.close(); } } catch (Exception e) { } if (connexion != null) { try { connexion.getConnect().close(); } catch (Exception e) { e.printStackTrace(); } } } return str; }
Comment faire pour créer des connexions à différentes bases de données successivement?
Merci
Partager