Bonjour à tous, voilà ce que j'essaye de faire mais sans succès.
Je voudrais remplacer ce code si( qui fonctionne très bien!)
Code :
- public boolean check()throws java.rmi.RemoteException{
- Vector v = new Vector();
- String sQuery = "";
- String Acces = "";
- String acc = "";
- boolean check = false;
- sQuery= "select * from USERS";
- Statement sStat = null;
- Connection cCon = null;
- ResultSet myRs;
- try{
- Class cDriverOracle=Class.forName("oracle.jdbc.driver.OracleDriver" );
- Driver dDriverOracle=(java.sql.Driver)cDriverOracle.newInstance();
- DriverManager.registerDriver(dDriverOracle);
- String URL="jdbc:oracle:thin:@ldieu2:1521:security";
- String User="LDIEU";
- String Passd="*********";
- cCon=DriverManager.getConnection(URL,User,Passd);
- }
- catch(Exception e){
- System.out.println("--Problème de chargement du driver Oracle" );
- e.printStackTrace();
- }
- try{
- sStat=cCon.createStatement();
- myRs=sStat.executeQuery(sQuery);
- while (myRs.next() ){
- Acces = myRs.getString("LOGIN" );
- System.out.println(Acces);
- acc = "true";
- }
- /**if (acc.equals("" )){
- while (myRs.next() ){
- check = false;
- }
- }*/
- if (acc.equals("true" )){
- check = true;
- }
- sStat.close();
- }
- catch(Exception sqlE){
- System.out.println("La requête n'à pas obouti" );
- sqlE.printStackTrace();
- }
- return check;
- }
|
Par ce code ci, car je voudrais enlever tous les éléments de connexion, afin de rendre mon code plus portable, en cas de changment de username,...
Code :
- public boolean check()throws java.rmi.RemoteException{
- try {
- javax.naming.Context context = new javax.naming.InitialContext();
- try {
- dataSource = (DataSource) context.lookup("java:comp/env/jdbc/DataSource" );
- }
- catch(Exception e) {
- throw new EJBException("Error looking up dataSource: " + e.toString());
- }
- }
- catch(Exception e) {
- throw new EJBException("Error initializing context:" + e.toString());
- }
- String sQuery = "";
- String Acces = "";
- String acc = "";
- boolean check = false;
- sQuery= "select LOGIN from USERS where FIRST_NAME= Leroy ";
- Connection cCon = null;
- Statement sStat = null;
- ResultSet myRs;
- try {
- cCon= dataSource.getConnection();
- sStat=cCon.createStatement();
- myRs = sStat.executeQuery(sQuery);
- while (myRs.next() ){
- Acces = myRs.getString("LOGIN" );
- System.out.println("Login: "+Acces);
- acc = "true";
- }
- if (acc.equals("true" )){
- check = true;
- }
- sStat.close();
- }
- catch(Exception sqlE){
- System.out.println("La requête n'à pas obouti" );
- sqlE.printStackTrace();
- }
- return check;
- }
|
Mais sa ne fonctionne pas, j'ai pourtant bien crée mon pool de connection DataSource sous JBuilder, mais sa ne fonctionne pas, il m'affiche des problèmes concernant DataSource !!
Voilà le code de retour que j'ai lorsque je fais un RUN du client test:
Code :
- -- Calling check()
- java.rmi.RemoteException: EJB Exception: ; nested exception is:
- javax.ejb.EJBException: Error initializing context:javax.ejb.EJBException: Error looking up dataSource: javax.naming.NameNotFoundException: While trying to look up comp/env/jdbc/DataSource in /app/ejb/CECUSesMod.jar#CECUSes.; remaining name 'comp/env/jdbc/DataSource'
- at weblogic.rjvm.BasicOutboundRequest.sendReceive(BasicOutboundRequest.java:108)
- at weblogic.rmi.cluster.ReplicaAwareRemoteRef.invoke(ReplicaAwareRemoteRef.java:290)
- at weblogic.rmi.cluster.ReplicaAwareRemoteRef.invoke(ReplicaAwareRemoteRef.java:247)-- Failed : check()
- at cecusesproject.CECUSes_e3q30w_EOImpl_814_WLStub.check(Unknown Source)
- at cecusesproject.CECUSesTestClient2.check(CECUSesTestClient2.java:196)
- at cecusesproject.CECUSesTestClient2.main(CECUSesTestClient2.java:24)
- Caused by: javax.ejb.EJBException: Error initializing context:javax.ejb.EJBException: Error looking up dataSource: javax.naming.NameNotFoundException: While trying to look up comp/env/jdbc/DataSource in /app/ejb/CECUSesMod.jar#CECUSes.; remaining name 'comp/env/jdbc/DataSource'
- at cecusesproject.CECUSesBean.check(CECUSesBean.java:65)
- at cecusesproject.CECUSes_e3q30w_EOImpl.check(CECUSes_e3q30w_EOImpl.java:45)
- at cecusesproject.CECUSes_e3q30w_EOImpl_WLSkel.invoke(Unknown Source)
- at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:477)
- at weblogic.rmi.cluster.ReplicaAwareServerRef.invoke(ReplicaAwareServerRef.java:108)
- at weblogic.rmi.internal.BasicServerRef$1.run(BasicServerRef.java:420)
- at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:363)
- at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:147)
- at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:415)
- at weblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest.java:30)
- at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:219)
- at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:178)
- -- Return value from check(): false.
|
Merci a tous pour votre aide, car je suis perdu !
Message édité par Devil6662 le 08-04-2005 à 12:22:24