- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个关于性能的问题。
我开发的应用程序是 Spring MVC 应用程序 (v3.2.9)。它托管在 WebSphere Application Server (v8.5.5) 上。它连接到 AS400 DB2 系统(驱动程序是 JTOpen v9.1)。我的应用程序调用 IBM AS400 系统上的存储过程。它是使用 Spring 的 JdbcTemplate.execute 方法调用的。代码如下:
jdbcTemplate.execute(new CallableStatementCreator() {
@Override
public CallableStatement createCallableStatement(Connection con) throws SQLException {
CallableStatement cs = con.prepareCall("{CALL XXXXXXSP ( ?, ? )}");
cs.setString(1, xxx);
cs.setString(2, xxx);
return cs;
}
},
new CallableStatementCallback<String>() {
@Override
public String doInCallableStatement(CallableStatement cs)throws SQLException, DataAccessException {
cs.execute();
return null;
}
});
我们遇到了一些问题,调用此过程偶尔会引发错误“[SQL0501] Cursor C1 not open”打开日志记录并检查后,看起来只有当应用程序尝试重新启动时才会发生此错误- 使用 CallableStatement。上次使用此 CallableStatement 时,相应的游标已关闭,这会导致错误(我不能 100% 确定此重用是否是预期行为)。该错误每天大约发生 20 次,这是一个相对较低的百分比,因为该应用程序的流量要高得多。
我的问题是,在cs.execute();
之后的代码中添加cs.close();
会导致代码性能下降吗?
最佳答案
一般情况下应该调用close()方法来关闭语句,因为它会释放资源。这没有任何问题。
但是JdbcTemplate为你关闭了声明,所以不需要它。
这是 JdbcTemplate 在执行结束时所做的事情 execute(CallableStatementCreator csc, CallableStatementCallback<T> action)
方法:
JdbcUtils.closeStatement(cs);
DataSourceUtils.releaseConnection(con, getDataSource());
来自 CallableStatementCallback api :
doInCallableStatement(CallableStatement cs) throws SQLException ,DataAccessException
Gets called by JdbcTemplate.execute with an active JDBC CallableStatement. Does not need to care about closing the Statement or the Connection, or about handling transactions: this will all be handled by Spring's JdbcTemplate. NOTE: Any ResultSets opened should be closed in finally blocks within the callback implementation. Spring will close the Statement object after the callback returned, but this does not necessarily imply that the ResultSet resources will be closed: the Statement objects might get pooled by the connection pool, with close calls only returning the object to the pool but not physically closing the resources.
关于java - CallableStatement.close() 会导致性能问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44954196/
CallableStatement stmt = getSession().connection().prepareCall( "{call CRM_DAO.Sear
public void XXX(){ Connection conn = ~~; CallableStatement cstmt = conn.prepareCall("
我在 Oracle 11g 中有一个存储过程,我使用 Oracle 瘦数据库驱动程序和 CallableStatement 从 Java 程序调用它。此存储过程在同一连接上的循环中被调用数千次。 对于
当调用没有参数且没有输出的存储过程时,使用 CallableStatement 有什么优势吗?超过常规Statement或PreparedStatement ? 最佳答案 CallableStatem
我是java新手。我尝试在 SQL SERVER 中创建一个存储过程(SP)。SP 是: go create procedure sp_calculate @value1 int = 0,
我有一个存储过程,需要大约 3 小时才能执行。我不想等到 procedure 返回值或等到 CallableStatement execute() 方法被执行。 JDBC中有这种可能性吗?或者我应该使
我有一个如下形式的 SQL 语句: BEGIN\n UPDATE tab SET stuff WHERE stuff RETURNING intA, intB, stringC INTO ?,?,?
我在 MySql 中有一个存储过程的示例,我想用 JDBC 调用它。问题是我收到以下错误: java.sql.SQLException: Parameter number 1 is not an OU
我有一个关于性能的问题。 我开发的应用程序是 Spring MVC 应用程序 (v3.2.9)。它托管在 WebSphere Application Server (v8.5.5) 上。它连接到 AS
我试图通过参数名称调用存储过程: int processId = 1; CallableStatement stmt = conn.prepareCall("{call get_process_log
我在我的应用程序中使用此方法来获取特定组织的子组织。它调用一个存储过程(创建一个临时表)。 StoredProcedureDAO.java private Connection dbConnectio
我试图调用一个带有指定参数名称的存储过程,但 JDBC 无法接受这些参数。它说: 方法 org.postgresql.jdbc4.Jdbc4CallableStatement.setObject(St
假设有一些 Oracle PL/SQL 过程,它接收 IN 参数并返回 OUT 游标参数。我有一个执行此过程的 jdbc 代码: DataSource dataSource; //dataso
我有这个 Java 代码: Connection conn = connectionProvider.getConnection(); statement = conn.prepareCall("ex
要在 Java 中仅使用简单的 JDBC 调用 Oracle 的存储过程,我们可以这样做: con.prepareCall("{ call ? = my_procedure(?) }"); callS
我正在遵循有关可调用语句的指南。 在本指南中,它说我需要使用以下语句注册 out 参数: callsts.registerOutParameter(2, java.sql.Types.VARCHAR)
当我从命令行调用存储过程时,我得到以下信息。 CALL `events`.`get_event_by_id`(10) +---------+----------+-------------+-----
需要有关 JDBC 查询的一些帮助。我本来想亲自尝试一下,但现在我无法访问数据库。 我的问题是:既然CallableStatement扩展了PreparedStatement,这是否意味着我们可以使用
我有一个 Java 应用程序,对通过网络接收的 UTF-8 编码的 String 进行解码,并将其保存到我的数据库 (SQL Server 2000) 中的 varchar 列中。我使用 JDBC 的
我在调用不返回任何内容的函数时出现 Java 异常: org.postgresql.util.PSQLException: A CallableStatement was executed with
我是一名优秀的程序员,十分优秀!