Java错误-[BEA][Oracle JDBC Driver]No ResultSet set was produced.

前两天调试一段 JAVA 代码,调试过程中系统出现错误,错误如下:


1,由于该环境连接了Weblogic,刚开始以为是weblogic 出了问题,后来发现与weblogic没有关系

2,仔细查看了出问题的地方,相关代码为

CallableStatement cstmt = null;
		Session session = null;
		try {
			session = this.getHibernateTemplate().getSessionFactory()
					.openSession();
			conn = session.connection();// .getConnection();
			cstmt = conn.prepareCall("{call P_Initiate(?,?)}");
			cstmt.setString(1, strRq);
			cstmt.registerOutParameter(2, java.sql.Types.INTEGER);
			cstmt.executeQuery();

代码在执行 executeQuery方法抛出异常

3,核查了 存储过程 P_Initiate ,发现该存储过程 返回类型为 int 类型,这个与代码调用传递一致。

4,网上查询了下,发现问题所在

    executeQuery(sql) 用于执行查询语句  会返回所要查询的result集合
    executeUpdate(sql)用于执行insert、delete、update语句,返回受影响的情况

5,调整最后一行代码为 

cstmt.executeUpdate();

错误解决。

扫描二维码关注公众号,回复: 2498973 查看本文章

其他

根据调查结果,除了采用上述处理外,还可采用

cstmt.execute();

进行相应处理。

唯一区别是 

executeUpdate 以数值类型返回处理的结果条数,或者存储过程的返回值

execute 以bool类型返回是否查询模式,查询模式返回 true,增、删、改,调用存储过程则返回false


猜你喜欢

转载自blog.csdn.net/mystonelxj/article/details/81027977