【问题标题】:EclipseLink Native API not working with SQLserverEclipseLink Native API 不能与 SQLserver 一起使用
【发布时间】:2012-03-22 12:35:09
【问题描述】:

在我们的 Struts2-Spring 应用程序中,我们使用以下代码行访问该过程

ServerSession serverSession = null;
ClientSession cSession = null;

            serverSession = (ServerSession) SessionManager.getManager().getSession("db_session"); 
            cSession =serverSession .acquireClientSession();

            StoredProcedureCall call = new StoredProcedureCall();
            call.setProcedureName("usp_list_dept_users");
            call.addNamedArgumentValue("p_user_id", user_id);
            call.useNamedCursorOutputAsResultSet("RCT1");
            List<DatabaseRecord> list = cSession.executeSelectingCall(call);
            ListIterator<DatabaseRecord> litr = list.listIterator();
--------------
-------------
-------------

此代码适用于 oracle 数据库。但是连接 SQLserver db 时相同的代码不起作用

List<DatabaseRecord> list = cSession.executeSelectingCall(call);

抛出nullpointerexception

以下是用于连接SQLserver的Session.xml内容

<session xsi:type="server-session">
      <name>db_session</name>
      <event-listener-classes/>
      <logging xsi:type="toplink-log"/>

      <login xsi:type="database-login">
         <platform-class>org.eclipse.persistence.platform.database.SQLServerPlatform</platform-class>
         <user-name>sa</user-name>
         <password>testpwd</password>
         <sequencing>
            <default-sequence xsi:type="native-sequence">
               <name>Native</name>
            </default-sequence>
         </sequencing>
         <driver-class>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver-class>
         <connection-url>jdbc:sqlserver://172.16.12.7:1433;databaseName=stdentlist</connection-url>
      </login>
      <connection-pools>
         <read-connection-pool>
            <name>ReadConnectionPool</name>
         </read-connection-pool>
         <write-connection-pool>
            <name>default</name>
         </write-connection-pool>
      </connection-pools>
      <connection-policy/>
   </session>

【问题讨论】:

    标签: java sql-server spring eclipselink


    【解决方案1】:

    堆栈跟踪会有所帮助,但是,存储过程是非常特定于数据库的。

    call.useNamedCursorOutputAsResultSet("RCT1");

    这在 SQL Server 上没有意义,因为它没有游标输出参数,我假设您的存储过程定义在 SQL Server 上非常不同,因此您将需要不同的调用。 SQL Server 可以从存储过程中返回结果集,所以可能只是删除游标出来的。

    还要确保存储过程存在于数据库中。

    【讨论】:

    • 是的,它有效。谢谢。仍然不知道为什么所有问题都出现在另一行(异常)。
    猜你喜欢
    • 2016-12-27
    • 2019-05-21
    • 1970-01-01
    • 1970-01-01
    • 2021-06-24
    • 2013-06-24
    • 2012-11-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多