【发布时间】:2012-11-24 14:05:27
【问题描述】:
我有以下代码。当我传递像“firstname lastname”这样的普通字符串时。存储过程很快就会返回。但是当我用 firstname* 调用它时,它需要很多时间。当我使用 firstname* 执行存储过程时,不会超过 2 秒。下面是代码
public List<NameBean> getNameReportJson(final int numberOfResults,
final String searchValue, final String category, Connection con)
throws SQLException {
final List<NameBean> beanList = new ArrayList();
List<String> resultStrs = new ArrayList<String>();
final String nameReportStoreProcedure = "{call [sp_SENTRY_INFORMATION_REPORT_NAME_REPORT] (?,?,?,?,?)}";
Session session = (Session) em.getDelegate();
StringBuffer sb = new StringBuffer();
session.doWork(new Work() {
@Override
public void execute(Connection connection) throws SQLException {
CallableStatement cstmt = connection
.prepareCall(nameReportStoreProcedure);
ResultSet rs = null;
cstmt.setInt("numberOfResults", numberOfResults);
cstmt.setString("SearchValue", searchValue);
cstmt.setString("Category", category);
cstmt.setDate("startDate", null);
cstmt.setDate("endDate", null);
rs = cstmt.executeQuery();
logger.debug("CeReport the ResultSet is: " + rs);
while (rs.next()) {
NameBean nameBean = new NameBean();
String oriName = rs.getString("ORIGINAL NAME");
String standName = rs.getString("STANDARDIZED NAME");
String groupName = rs.getString("GROUP NAME");
long groupId = rs.getLong("GROUP ID");
nameBean.setOriginalName(oriName);
nameBean.setStandardName(standName);
nameBean.setGroupName(groupName);
nameBean.setGroupID(groupId);
nameBean.setEntityID(rs.getString("ENTITY ID"));
beanList.add(nameBean);
}
}
});
return beanList;
}
【问题讨论】:
-
也许它来自您的应用程序中配置的事务类型,我们缺少一些信息......
-
我在任何地方都看不到任何交易。我查看了存储过程及其一堆带有连接的选择。这也是在一个网络应用程序中,它有一个关于它的 REST 端点
-
数据库上没有其他运行?什么是分贝?您是否尝试过更改 jdbc 驱动程序?事实上,你能检查一下建立与数据库的连接没有延迟吗?
标签: java hibernate stored-procedures jdbc callable-statement