我想使用 jmeter 测试 Oracle 存储过程。我已经完成了除参数之外的所有操作。
这是我的 SQL 查询:
declare outinfo varchar2(20); outtable sys_refcursor; begin {call RK_JSCX(?,?)}; end;
Oracle中的outtable是一个游标,我在java中使用resultSet来包含它,但是无论我在参数类型中设置什么,它都说无效类型。
Sample Start: 2012-10-25 16:06:41 CST Load time: 0 Latency: 0 Size in bytes: 25 Headers size in bytes: 0 Body size in bytes: 25 Sample Count: 1 Error Count: 1 Response code: null 0 Response message: java.sql.SQLException: Invalid data type: cursor
响应头: oracle.jdbc.driver.T4CConnection@58ba09
示例结果字段: 内容类型:文本/纯文本 数据编码:UTF-8
如何解决? 谢谢!
这是我的java代码:
public String RK_JSCX() throws Exception {
RK_JSCX_Response response = null;
List<RK_JSCX_Outtable> list = null;
Connection con = null;
CallableStatement cs = null;
ResultSet rs = null;
String sql = null;
try {
sql = "{call RK_JSCX(?,?)}";
con = ConnectionUtils.getInstance().getConnect();
if (con.isClosed()) {
throw new IllegalStateException("ERROR.THE CONNECTION ISCLOSED");
}
cs = con.prepareCall(sql);
cs.registerOutParameter(1, oracle.jdbc.OracleTypes.CURSOR);
cs.registerOutParameter(2, Types.VARCHAR);
cs.execute();
rs = (ResultSet) cs.getObject(1);
list = new ArrayList<RK_JSCX_Outtable>();
while (rs.next()) {
RK_JSCX_Outtable out = new RK_JSCX_Outtable(rs.getString(1), rs.getString(2), rs.getString(3), rs.getString(4), rs.getInt(5), rs.getString(6));
list.add(out);
}
String outInfo = cs.getString(2);
response = new RK_JSCX_Response(list, outInfo);
} catch (SQLException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}finally {
try {
if (rs != null) {
rs.close();
if (cs != null) {
cs.close();
}
if (con != null) {
con.close();
}
}
} catch (SQLException e) {
System.out.println("Exception2");
e.printStackTrace();
}
}
return JSON.toJSONString(response);
}
最佳答案
这是怎么做的:
SQL 查询:调用 RK_JSCX(?,?)
参数值:OUT, OUT
参数类型:OUT -10,OUT VARCHAR
-10 是 OracleTypes.CURSOR 的 int 值
变量名:cursor、outInfo
Names are what you want
JMeter 允许使用比 java.sql.Types 常量更多的类型,在这种情况下,您不使用常量名称,而是使用常量的整数值。
文档已经澄清(在下一个 JMeter 版本中),请参阅:
关于oracle - 如何使用 jmeter 测试具有 sys_refcursor 返回类型的 Oracle 存储过程?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13026140/