如何使用jmeter测试具有sys_refcursor返回类型的Oracle存储过程?
我想使用jmeter测试Oracle存储过程.除参数外,我已完成所有操作.
I want to test an Oracle Stored Procedure by using jmeter.I have done everything but parameters.
这是我的SQL查询:
声明 outinfo varchar2(20); outtable sys_refcursor; 开始 {致电RK_JSCX(?,?)}; 结束;
declare outinfo varchar2(20); outtable sys_refcursor; begin {call RK_JSCX(?,?)}; end;
Oracle中的outtable是一个游标.我使用resultSet将其包含在java中.但是,无论我在参数类型中设置了什么,它都表示无效类型.
The outtable in Oracle is a cursor.And i used resultSet to contain it in java.However,whatever i set in parameter types ,it said invalid type.
示例开始时间:2012-10-25 16:06:41 CST 载入时间:0 延迟:0 字节大小:25 标头大小(以字节为单位):0 正文大小(以字节为单位):25 样本数:1 错误计数:1 响应码:null 0 响应消息:java.sql.SQLException:无效的数据类型:游标
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
Response headers: oracle.jdbc.driver.T4CConnection@58ba09
SampleResult字段: ContentType:文本/纯文本 数据编码:UTF-8
SampleResult fields: ContentType: text/plain DataEncoding: UTF-8
如何解决? 谢谢!
How can fix it? Thanks!
这是我在Java中的代码:
Here is my code in 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(?,?)
SQL Query : call RK_JSCX(?,?)
参数值:OUT,OUT
Parameter values : OUT, OUT
参数类型:OUT -10,OUT VARCHAR
Parameter types : OUT -10,OUT VARCHAR
-10是OracleTypes.CURSOR的int值
-10 being the int value of OracleTypes.CURSOR
变量名称:cursor,outInfo
Variable names: cursor, outInfo
Names are what you want
JMeter允许使用比java.sql.Types常量更多的类型,在这种情况下,您可以使用常量的整数值来代替常量名称.
JMeter allows using more types than java.sql.Types constants, in this case instead of using Constant names, you use integer values of constants.
文档已经澄清(在下一版JMeter中),请参见:
Documentation has been clarified (in next JMeter version) , see: