Salut
je suis débutante en java et je veux me connecter à la base de donnée de openerp j'ai utilisé ce code:


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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
import java.net.MalformedURLException;
import java.util.ArrayList;
import java.net.URL;
import java.util.HashMap;
import java.util.Vector;
import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.client.XmlRpcClient;
import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
 
public class OpenERP {
	// connection
	private XmlRpcClient xmlrpc;
	// userid, derived from first login
	private int openERPuserid;
	// internally stored
	private String openERPHost;
	private int openERPPort;
	private static int default_openERPPort = 8069;
	private String openERPDB;
	private String openERPUser;
 
	private String openERPPassword; // esp. the password is needed for every request
 
	public void OpenERP(String host, int port) {
		openERPHost = host;
		openERPPort = port;
        }
public OpenERP(String host) {
 
		openERPHost = host;
		openERPPort = default_openERPPort;
}
 
public OpenERP(String host, int port, String db, String user, String pass) throws MalformedURLException, XmlRpcException {
 
		openERPHost = host;
		openERPPort = port;
		openERPDB = db;
		openERPUser = user;
		openERPPassword = pass;
 
		loginOpenERP();
		initializeXMLRPC();
 
	}
public OpenERP(String host, String db, String user, String pass) throws MalformedURLException, XmlRpcException {
 
		openERPHost = host;
		openERPPort = default_openERPPort;
		openERPDB = db;
		openERPUser = user;
		openERPPassword = pass;
 
		loginOpenERP();
		initializeXMLRPC();
 
	}
public String[] list() throws MalformedURLException, XmlRpcException {
 
		XmlRpcClient xmlrpcLogin = new XmlRpcClient();
		XmlRpcClientConfigImpl xmlrpcConfigLogin = new XmlRpcClientConfigImpl();
 
		xmlrpcConfigLogin.setEnabledForExtensions(true);
		URL serverURL = null;
		// processing is done with /db, unlike login (/common) or queries (/object)
		serverURL = new URL("http", openERPHost, openERPPort, "/xmlrpc/db");
 
		xmlrpcConfigLogin.setServerURL(serverURL);
		xmlrpcLogin.setConfig(xmlrpcConfigLogin);
 
		// Connect
		Object[] params = new Object[] {};
		Object id = xmlrpcLogin.execute("list", params);
		Object[] ids = (Object[]) id;
 
		String[] strs = new String[ids.length];
 
		for (int i = 0; i < ids.length; i++) {
			Object idsi = ids[i];
			strs[i] = (String)idsi;
		}
		return strs;
 
	}
public boolean loginOpenERP(String username, String password) throws MalformedURLException, XmlRpcException {
		openERPUser = username;
		openERPPassword = password;
		return loginOpenERP();
	}
public boolean loginOpenERP() throws MalformedURLException, XmlRpcException {
		XmlRpcClient xmlrpcLogin = new XmlRpcClient();
 
		XmlRpcClientConfigImpl xmlrpcConfigLogin = new XmlRpcClientConfigImpl();
 
		xmlrpcConfigLogin.setEnabledForExtensions(true);
		URL serverURL = null;
		// processing is done with /common, unlike queries (/object)
 
		serverURL = new URL("http", openERPHost, openERPPort, "/xmlrpc/common");
 
		xmlrpcConfigLogin.setServerURL(serverURL);
		xmlrpcLogin.setConfig(xmlrpcConfigLogin);
		// Conect
 
		Object[] params = new Object[] { openERPDB, openERPUser, openERPPassword };
		Object id = xmlrpcLogin.execute("login", params);
		if (id instanceof Integer)
			openERPuserid = ((Integer) id).intValue();
 
		// return "true" if user id exists
		return (openERPuserid > 0);
	}
private void initializeXMLRPC() throws MalformedURLException {
 
		xmlrpc = new XmlRpcClient();
 
 
		XmlRpcClientConfigImpl xmlrpcConfig = new XmlRpcClientConfigImpl();
 
		xmlrpcConfig.setEnabledForExtensions(true);
		URL serverURL = null;
		serverURL = new URL("http", openERPHost, openERPPort, "/xmlrpc/object");
		xmlrpcConfig.setServerURL(serverURL);
		xmlrpc.setConfig(xmlrpcConfig);
 
	}
 
	public boolean isConnected() 
		// return "true" if user id exists
		return (openERPuserid > 0);
 
	}
 
	public boolean hasModule(String modulename, boolean isInstalled) {
		OpenERPDomain domain = new OpenERPDomain();
		domain.add("name","=",modulename);
		if (isInstalled) {
 
			domain.add("state","=","installed");
		}
 
		// use a simple search on the module model/table
		Object[] is = search("ir.module.module", domain);
		return ((is != null) && (is.length > 0));
 
	}
 
 
	public boolean hasModule(String modulename) {
		return hasModule(modulename, true);
 
	}
 
	private Vector<Object> createParams(String model, String action) {
 
		Vector<Object> params = new Vector<Object>();
		params.add(openERPDB);
		params.add(openERPuserid);
		params.add(openERPPassword);
		params.add(model);
		params.add(action);
		return params;
 
	}
 
	public Object[] search(String model, OpenERPDomain domain) {
		return search(model, domain.get());
 
	}
 
 
	public Object[] search(String model, Object[] domain) {
		Vector<Object> params = createParams(model, "search");
		params.add(domain);
		params.add(0); // offset
		params.add(new Double(2 ^ 63 - (2 ^ 9 + 1))); // maximal results. should
														// be enough, I think :)
 
 
		params.add(0);  // another 0. is this offset to the results size? but what would the first 0 be then?
 
						// if you know what this is, please tell me :)
		Object[] resultArray = null;
 
		try {
			Object result = xmlrpc.execute("execute", params);
			resultArray = (Object[]) result;
		} catch (XmlRpcException e) {
			// TODO Auto-generated catch block
 
			e.printStackTrace();
 
		}
 
		return resultArray;
	}
 
 
 
	public Object[] read(String model, Object[] readlist, String[] fieldlist) {
 
		Vector<Object> params = createParams(model, "read");
		params.add(readlist);
		params.add(fieldlist);
 
		Object[] resultArray = null;
 
		try {
 
			Object result = xmlrpc.execute("execute", params);
 
			resultArray = (Object[]) result;
 
		} catch (XmlRpcException e) {
 
			// TODO Auto-generated catch block
 
			e.printStackTrace();
 
		}
 
		return resultArray;
 
	}
 
	public OpenERPRecordSet readRecords(String model, Object[] readlist, String[] fieldlist) {
 
		return new OpenERPRecordSet(this.read(model, readlist, fieldlist));
 
	}
 
	public Integer create(String model, HashMap<String, Object> data) {
 
		Vector<Object> params = createParams(model, "create");
 
		params.add(data);
 
 
		Integer resultID = null;
 
		try {
 
			Object result = xmlrpc.execute("execute", params);
 
			resultID = (Integer) result;
 
		} catch (XmlRpcException e) {
 
			// TODO Auto-generated catch block
 
			e.printStackTrace();
 
		}
 
 
		return resultID;
 
 
	}
 
	public Boolean write(String model, Integer id, HashMap<String, Object> values) {
 
		return write(model, new Integer[] { id }, values);
 
	}
 
 
	public Boolean write(String model, Integer[] ids, HashMap<String, Object> values) {
 
		Vector<Object> params = createParams(model, "write");
 
		params.add(ids);
 
		params.add(values);
 
 
		Boolean resultID = null;
 
		try {
 
			Object result = xmlrpc.execute("execute", params);
			resultID = (Boolean) result;
 
		} catch (XmlRpcException e) {
 
			// TODO Auto-generated catch block
 
			e.printStackTrace();
 
		}
 
 
		return resultID;
 
 
	}
 
 
}
Mais lors de la compilation ça donne : Erreur*: Impossible de trouver la classe Login principale
SVP veuillez m'aider