9 Replies Latest reply on Dec 27, 2011 5:02 PM by 906570

    Data Source getConnection Fails!! - Please Help

    906570

      Hi All,
      I have created a JDBC Data Source on WebLogic9.2 with jdbc:oracle:thin:@localhost:1521:testdev and configured from the WebLogic Console
      I have created a java client to connect to the DS and wrote the following code

      DataSource ds=null;
      Connection conn=null;
      Statement stmt=null;
      ResultSet rs=null;
      Context ctx=null;

      try
      {
      Hashtable ht = new Hashtable();
      ht.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
      ht.put(Context.PROVIDER_URL, "t3://localhost:7001");
      ctx=new InitialContext(ht);
      ds=(DataSource)ctx.lookup("myTestDS");
      conn=ds.getConnection("dmadmin", "passme");
      stmt=conn.createStatement();
      rs=stmt.executeQuery("SELECT * FROM USER_TABLES");

      while (rs.next())
      {
      System.out.println("Result: " + rs.getString(1));
      }
      }catch (Exception e) {
      System.out.println("Error in Main "+e.toString());
      e.printStackTrace();
      }
      finally
      {
      try{
      if(rs!=null) rs.close();
      if(stmt!=null) stmt.close();
      if(conn!=null) conn.close();
      if(ds!=null) ds=null;
      if(ctx!=null) ctx.close();
      }catch (SQLException e) {
      System.out.println("Error in SQLException Finally "+e.toString());
      }
      catch (NamingException e) {
      System.out.println("Error in NamingException Finally "+e.toString());
      }
      }
      }

      It runs into errors at the getConnection(user, password) statement with

      Error in Main java.sql.SQLException: User: fairisaac_e2e, failed to be authenticated.
      java.sql.SQLException: User: dmadmin, failed to be authenticated.
      at weblogic.rjvm.ResponseImpl.unmarshalReturn(ResponseImpl.java:211)

      If I try getConnection(), it fails as

      Error in Main weblogic.rmi.extensions.RemoteRuntimeException: Unexpected Exception
      weblogic.rmi.extensions.RemoteRuntimeException: Unexpected Exception
      at weblogic.jdbc.common.internal.RmiDataSource_922_WLStub.getConnection(Unknown Source)

      Any pointers is highly appreciated

      Thanks
      Raj

        • 1. Re: Data Source getConnection Fails!! - Please Help
          EJP
          Error in Main java.sql.SQLException: User: fairisaac_e2e, failed to be authenticated.
          Either 'fairisaac_e2e' or the password you supplied with it was incorrect.
          java.sql.SQLException: User: dmadmin, failed to be authenticated.
          Either 'dmadmin_e2e' or the password you supplied with it was incorrect.
          • 2. Re: Data Source getConnection Fails!! - Please Help
            906570
            Hi,

            Thanks for the reply

            1) getConnection(user, password) fails with user authentication
            I have checked the 'Test Connection' with the same user and password
            and it was connected in Console. Not sure if I should give 'Encrypted' password etc. Please advise

            2) getConnection() fails with an error I can't follow. Please see
            Error in Main weblogic.rmi.extensions.RemoteRuntimeException: Unexpected Exception
            weblogic.rmi.extensions.RemoteRuntimeException: Unexpected Exception
            at weblogic.jdbc.common.internal.RmiDataSource_922_WLStub.getConnection(Unknown Source)


            Raj
            • 3. Re: Data Source getConnection Fails!! - Please Help
              gimbal2
              903567 wrote:
              Hi,

              Thanks for the reply

              1) getConnection(user, password) fails with user authentication
              I have checked the 'Test Connection' with the same user and password
              and it was connected in Console. Not sure if I should give 'Encrypted' password etc. Please advise
              So through one path it works and through another it doesn't. Hmmmmmmmmm.

              I know! You are mistaken, there is a difference in the way the connection is made. For one, through the application server you use a datasource while through the console you probably do not. Check, double check and triple check all the configuration, there must be a mistake somewhere. It can be something as stupid as an added space. For a true Friday afternoon facepalm: are you sure you are connecting to the correct database?

              2) getConnection() fails with an error I can't follow. Please see
              Error in Main weblogic.rmi.extensions.RemoteRuntimeException: Unexpected Exception
              weblogic.rmi.extensions.RemoteRuntimeException: Unexpected Exception
              at weblogic.jdbc.common.internal.RmiDataSource_922_WLStub.getConnection(Unknown Source)
              If you can't explain it, nobody can. You have access to the system and the logs and there is zero information in this piece of stacktrace other than "it didn't work". But focus on problem 1), 'fixing' that will probably make this one go away as well.
              • 4. Re: Data Source getConnection Fails!! - Please Help
                Joe Weinstein-Oracle
                I'm just the nobody for the job ;)

                WebLogic DataSources are to be accessed via the parameterless getConnection() call, usually.
                The getConnection(user, password) method is usually superfluous because the pool already
                has the DBMS user/password to make connections. So WebLogic implements the user/password
                method to mean the WebLogic user/password. This is useful when you apply access controls
                on your DataSources, so not all WebLogic users can access the DataSource. Then, you can, for
                instance write your JSPs with code like getConnection(weblogic_user, weblogic_password) so
                everyone can execute your JSPs and get the full functionality you code, but none of them
                can independently use the DataSource.
                • 5. Re: Data Source getConnection Fails!! - Please Help
                  906570
                  Hi,

                  1)

                  Java Client Accessing the Database through DriverManager - Works!!

                       Class.forName ("oracle.jdbc.OracleDriver");
                                 
                       conn = DriverManager.getConnection ("jdbc:oracle:thin:@" + DEVHOST + ":" +
                            DEVPORT + ":" + DEVDATABASE, DEVUSER, DEVUSER_PASSWORD);

                       stmt = conn.createStatement();
                       rset = stmt.executeQuery("SELECT * FROM REPORTS");
                       while (rset.next())
                       {
                       System.out.println (rset.getString(1));
                                 }
                       }
                            
                  2)

                  Java Client Accessing the Database through WebLogic 9.2 Configured Data Source - Fails

                       Hashtable ht = new Hashtable();
                       ht.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
                       ht.put(Context.PROVIDER_URL, "t3://localhost:7001");
                       ctx=new InitialContext(ht);
                       ds=(DataSource)ctx.lookup("myTestDS");
                       conn=ds.getConnection();
                                 
                       stmt=conn.createStatement();
                       rs=stmt.executeQuery("SELECT * FROM REPORTS");
                       while (rs.next())
                       {
                       System.out.println("Result: " + rs.getString(1));
                       }
                            
                  Uses the WebLogic 9.2 Host under T3 protocol - gives error as

                  Error in myTest weblogic.rmi.extensions.RemoteRuntimeException: Unexpected Exception
                  weblogic.rmi.extensions.RemoteRuntimeException: Unexpected Exception
                  at weblogic.jdbc.common.internal.RmiDataSource_922_WLStub.getConnection(Unknown Source)

                  Looks like the WebLogic Stub for DataSource is missing some thing

                  I read somewhere that Login is not enabled in the newly created DataSource
                  How to Enable Login ? (Via WebLogic, .......??)

                  Raj
                  • 6. Re: Data Source getConnection Fails!! - Please Help
                    Joe Weinstein-Oracle
                    For an external java client you would typically want to add the
                    weblogic user/password to the context, in order to connect
                    to weblogic.

                    Doing JDBC in an external client, through WebLogic to the
                    DBMS is not recommended. It's slow. Do it in a JSP etc. and
                    have your external clients get info in a lightweight way from
                    the JSP.
                    • 7. Re: Data Source getConnection Fails!! - Please Help
                      906570
                      Hi,
                      Thank you for your quick reply
                      I tried
                           Hashtable ht = new Hashtable();
                           ht.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
                           ht.put(Context.PROVIDER_URL, DEV_T3_URL);
                           ht.put(Context.SECURITY_PRINCIPAL, "weblogic");          
                           ht.put(Context.SECURITY_CREDENTIALS, "weblogic");          
                           ctx=new InitialContext(ht);
                                     
                           ds=(DataSource)ctx.lookup("aptTestDS");
                           conn=ds.getConnection();

                      The error is the same at
                      conn=ds.getConnection();

                      It fails if the WL Server is Not up or if the DataSource not specified correctly
                      This means that Connection to DS is good but getting the SQL session for the Database is the Issue
                      I have no clue about the WL Stub to the database/JDBC connection

                      I want to get this working and then try it in the JSP for our web applications

                      Appreciate your help

                      Raj
                      • 8. Re: Data Source getConnection Fails!! - Please Help
                        Joe Weinstein-Oracle
                        make sure that if there is any weblogic classes in the client classpath, that it is the exact
                        same version as the weblogic server you're trying to connect to. Try running the
                        program with zero weblogic classes in it's classpath.
                        • 9. Re: Data Source getConnection Fails!! - Please Help
                          906570
                          I tried the same code from my system as well as from the Weblogic server
                          The Error is the same. I need to use weblogic.jar on the client to instantiate
                          weblogic.jndi.WLInitialContextFactory

                          Not sure about the error
                          weblogic.rmi.extensions.RemoteRuntimeException: Unexpected Exception
                               at weblogic.jdbc.common.internal.RmiDataSource_922_WLStub.getConnection(Unknown Source)