Salut,
je debute avec Java et JDBC et g un pti souci...je vais essayer d´etre claire.
Voila g deux fichiers. Dans le premiers g les methodes suivantes:
ensuite je fais ma connections
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 /** * Methode qui lit le fichier Connection.properties dans lequel il y les *parametres de connexion. */ private Properties loadParams(String file) throws IOException { try{ // Loads a ResourceBundle and creates Properties from it Properties prop = new Properties(); ResourceBundle bundle = ResourceBundle.getBundle(file); Enumeration enumumeration = bundle.getKeys(); String key = null; while(enumumeration.hasMoreElements()) { key = (String)enumumeration.nextElement(); prop.put(key, bundle.getObject(key)); }} catch(Exception ex) { // Trap IO errors gui.putStatus("Error in reading the properties file "+'\n'+ex.toString()); } return prop; }
....mais cette partie du code appel une autre classe : OracleDataSource dans laquelle je dois implementer les methode suivantes....
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 public Connection dbConnection() throws Exception{ try { gui.putStatus("Trying to connect to the Database"); // Load the properties file to get the connection information Properties prop = loadParams("Connection"); // Create a OracleDataSource instance OracleDataSource ods = new OracleDataSource(); // Sets the driver type //ods.setDriverType("thin"); // Sets the database server name ods.setServerName((String)prop.get("HostName")); // Sets the database name ods.setDatabaseName((String)prop.get("SID")); // Sets the port number ods.setPortNumber(new Integer((String)prop.get("Port")).intValue()); // Sets the user name ods.setUser((String)prop.get("UserName")); // Sets the password ods.setPassword((String)prop.get("Password")); connection = ods.getConnection(); gui.putStatus("Connected to " + prop.get("SID") + " Database as " + prop.get("UserName")+". Please click on SELECT"+ " button to view records"); } catch(Exception ex) { // Trap SQL errors gui.putStatus("Error in Connecting to the Database "+'\n'+ex.toString()); } return connection; }
Comment configurer ces methodes??? Merci
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
55
56
57
58
59
60
61
62
63
64
65
66
67 public class OracleDataSource { public OracleDataSource() { /* try { // Loading JDBC driver Class.forName("com.mysql.jdbc.Driver"); // connection url String HostName = "jdbc:mysql://localhost:3306/test"; String UserName = "root"; String Password = "hello"; // Connexion Connection con = DriverManager.getConnection(HostName, UserName, Password); // Création d'une instruction Statement statement = con.createStatement(); // Query String query = "SELECT * FROM otn_airlines"; ResultSet resultset = statement.executeQuery(query); // Show results while(resultset.next()) { System.out.println(resultset.getString(1) + " " + resultset.getString(2) + " " + resultset.getString(3)); } // close connection con.close(); } catch( ClassNotFoundException e) { System.err.println("Erreur JDBC driver : " + e); } catch(SQLException sqle) { System.err.print("SQL error : " + sqle); } //return con; } //} public static void main(String[] args) { OracleDataSource oracledatasource = new OracleDataSource(); } } */ } public void setServerName(String string) { throw new UnsupportedOperationException("Not yet implemented"); } public void setDatabaseName(String string) { throw new UnsupportedOperationException("Not yet implemented"); } public void setPortNumber(int i) { throw new UnsupportedOperationException("Not yet implemented"); } public void setUser(String string) { throw new UnsupportedOperationException("Not yet implemented"); } public void setPassword(String string) { throw new UnsupportedOperationException("Not yet implemented"); } public Connection getConnection() { return null; } }
Partager