2017-06-14 5 views
0

WLS 12.1.3から接続プールから呼び出し可能ステートメントを使用することができ、以下のコードを使用して接続オブジェクトを取得しようと、私はない私は、データソースを作成している

、接続オブジェクトと呼び出し可能オブジェクトを記載している以下

 Hashtable ht = new Hashtable();   
     ht.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory"); 
     ht.put(Context.PROVIDER_URL, "t3://localhost:7001");    
     java.sql.Connection vendorConn = null; 
     try { 
      ctx = new InitialContext(ht); 
      javax.sql.DataSource ds 
        = (javax.sql.DataSource) ctx.lookup("jdbc/myDataSource"); 
      conn = ds.getConnection(); 
      } catch (SQLException e) { 
      LOGGER.error(e.getMessage()); 
      } 

weblogic.jdbc.rmi.SerialConnection_weblogic_jdbc_rmi_internal_ConnectionImpl_weblogic_jdbc_wrapper_JTAConnection_weblogic_jdbc_wrapper[email protected]d4 
cstmt = (weblogic.jdbc.rmi.SerialCallableStatement_weblogic_jdbc_rmi_internal_CallableStatementStub_weblogic_jdbc_rmi_internal_CallableStatementImpl_weblogic_jdbc_wrapper_CallableStatement_oracle_jdbc_driver_OracleCallableStatementWrapper_12130_WLStub) weblogic.jdbc.rmi.SerialCallableStatement_weblogic_jdbc_rmi_internal_CallableStatementStub_weblogic_jdbc_rmi_internal_CallableStatementImpl_weblogic_jdbc_wrapper_CallableStatement[email protected]145 

私が呼び出し可能

java.sql.SQLExceptionを使用して、ストアのプロシージャを呼び出したとき、私は以下の例外を取得しています:weblogic.rmi.extensions.RemoteRuntimeExceptionを:

Unexpected Exception 
    at weblogic.jdbc.rmi.SerialStatement.close(SerialStatement.java:126) 
    at weblogic.jdbc.rmi.SerialStatement.close(SerialStatement.java:110) 

    at weblogic.ejb.container.internal.MDListener.execute(MDListener.java:451) 
    at weblogic.ejb.container.internal.MDListener.transactionalOnMessage(MDListener.java:375) 
    at weblogic.ejb.container.internal.MDListener.onMessage(MDListener.java:310) 
    at weblogic.jms.client.JMSSession.onMessage(JMSSession.java:4855) 
    at weblogic.jms.client.JMSSession.execute(JMSSession.java:4529) 
    at weblogic.jms.client.JMSSession.executeMessage(JMSSession.java:3976) 
    at weblogic.jms.client.JMSSession.access$000(JMSSession.java:120) 
    at weblogic.jms.client.JMSSession$UseForRunnable.run(JMSSession.java:5375) 
    at weblogic.work.SelfTuningWorkManagerImpl$WorkAdapterImpl.run(SelfTuningWorkManagerImpl.java:548) 
    at weblogic.work.ExecuteThread.execute(ExecuteThread.java:311) 
    at weblogic.work.ExecuteThread.run(ExecuteThread.java:263) 
java.sql.SQLException: prepareStatement, Exception = Unexpected Exception 
    at weblogic.jdbc.rmi.RMIWrapperImpl.invocationExceptionHandler(RMIWrapperImpl.java:102) 
    at weblogic.jdbc.rmi.RMIStubWrapperImpl.invocationExceptionHandler(RMIStubWrapperImpl.java:34) 
    at weblogic.jdbc.rmi.SerialConnection.prepareStatement(SerialConnection.java:236) 


    at weblogic.ejb.container.internal.MDListener.execute(MDListener.java:451) 

示唆してくださいは、すべて私のSQL文が働いているが、手続きが呼び出さ取得されていないとも私はそれがsql.ConnectionにSerialConnectionを型キャストするために必要な必要があるデータソース接続を使用するには、この正しい方法です。

CallableStatement cst = null; 
      try { 
       cst = conn 
         .prepareCall("{call myProc(?,?,?,?,?,?,?,?)}"); 
       final String typeTableName = "studentdetails"; 

       cst.setInt(1, student.getEmpid()); 
       cst.setInt(2, student.getOrgid()); 
       cst.setInt(3, student.getYearid()); 
       cst.setString(4, student.getClassType()); 
       cst.setInt(5, student.getStudentid()); 
       cst.registerOutParameter(6, Types.ARRAY, typeTableName); 
       cst.registerOutParameter(7, java.sql.Types.VARCHAR); 
       cst.registerOutParameter(8, java.sql.Types.VARCHAR); 
           long startTime=System.currentTimeMillis(); 
       cst.execute(); 
           String dat=cst.getString(7); 
           //Array arr = cst.getArray(6); 
           long endTime=System.currentTimeMillis(); 

       if (null != cst.getObject(6)) { 
        data = (Object[]) ((Array) cst.getObject(6)).getArray(); 
       } 

私はデータソースを使用している場合は、私がnullとしてcst.getObject(6)を取得していますが、使用の通常のJDBC接続ならば、それは、オブジェクトを提供することで、正常に動作しています。

答えて

0

WebLogicを使用している場合は、その後、あなたは以下を加えることによって、デプロイメント記述子からのweb.xmlそれを参照する必要があり、あなたのweblogic.xmlの

<resource-description> 
    <res-ref-name>datasource_ref</res-ref-name> 
    <jndi-name>jdbc/myDataSource</jndi-name> 
</resource-description> 

に次の要素を追加する必要があります要素

次に、yからデータSrcを参照することができます私たちのようなJavaコードは、以下の、

Context cntxt= (Context)new InitialContext().lookup("java:comp/env"); 
DataSource ds= (DataSource)cntxt.lookup("datasource_ref"); 

またはリソースインジェクションを使用しては、以下の好き

@ApplicationScoped 
public class DBHandler{ 
    @Resource(name="datasource_ref") 
    private javax.sql.DataSource myDB; 

    public Connection getConnection(){ 
     return myDB.getConnection(); 
    } 
} 

そして、あなたはどこにでもCDI

DBHandler handler = CDI.current().select(DBHandler.class).get(); 

またはフィールドによってを使用してオンデマンドでそれを使用することができます注射

@Inject 
javax.enterprise.inject.Instance<DBHandler> instance; 
.... 
void persist(){ 
    DBHandler handler=instance.get(); 
    Connection con= handler.getConnection(); 
} 
+0

この接続はストアプロシージャコールをサポートしますか? – user3428736

+0

はい。ここでは、アプリケーションサーバーの接続プールからConnectionを単に埋めるだけです。アプリケーションサーバーのJDBC実装がストアドプロシージャ呼び出しをサポートしている限り、そこから呼び出されたConnectionはその機能をサポートする必要があります。 – TMtech

関連する問題