关于Jmeter中JDBC相关参数的应用

.数据库驱动类和URL格式:mysql

Database 正则表达式

Driver class 算法

Database URL sql

MySQL 数据库

com.mysql.jdbc.Driver apache

jdbc:mysql://host[:port]/dbname 缓存

PostgreSQL oracle

org.postgresql.Driver dom

jdbc:postgresql:{dbname} tcp

Oracle

oracle.jdbc.OracleDriver

jdbc:oracle:thin:@//host:port/service OR
        jdbc:oracle:thin:@(description=(address=(host={mc-name})(protocol=tcp)(port={port-no}))(connect_data=(sid={sid})))        

Ingres (2006)

ingres.jdbc.IngresDriver

jdbc:ingres://host:port/db[;attr=value]

SQL Server (MS JDBC driver)

com.microsoft.sqlserver.jdbc.SQLServerDriver

jdbc:sqlserver://host:port;DatabaseName=dbname

Apache Derby

org.apache.derby.jdbc.ClientDriver

jdbc:derby://server[:port]/databaseName[;URLAttributes=value[;...]]        

注:仅供参考

.相关参数

1.Variable Name

其中的Variable Name和上面JDBC Connection Configuration中的Variable Name相同,这里表示JDBC Connection Configuration 创建一个名为pubpool的链接池,以后其余JDBC Request 都共用这个链接池。

2.SQL Query

(1)Query Type

xxx Statement须要填写的sql是一句完整可执行的sql,而Prepared  xxx Statement容许用户在sql中使用??而后再Parameter valuesParameter types中填写参数和类型,最终执行时替代sql中的?,造成一句完整的sql语句。

Select statement:

##待验证,网上找的例子:

若是SQL语句中须要使用参数变量,那么Query Type 须要设置为Select Statement ,须要先添加Random Variable,而后在Parameter Values中输入${变量名称},${变量名称}

Paramter types中输入变量的数据类型。 以下图示:

中间用逗号分隔。只能执行第一个SQL语句。

Update statement: 对于InsertUpdateDelete语句,须要设置Query Type为:Update Statament.数据修改语句中可使用参数,并且能够顺序执行多个修改语句。

Egg

Callable statement

##待验证:

多个查询语句(不使用参数的状况下)能够放在一块儿顺序执行,须要设置Query TypeCallable Statement,而后顺序输入select语句,不用加go或者分号。若是Query Type设置为:Select Statement的话,只执行第一个SQL语句。

Prepared select statement:

Prepared update statement:

Commit

JDBC connection configuration中的自动提交为false,执行更改,增长或删除操做后,查询数据并没有更改,再添加一个JDBC Request,设置其Query Typecommit,再次查询,以前的操做生效。

Rollback

JDBC connection configuration中的自动提交为false,执行更改,增长或删除操做后,查询数据并没有更改(至关于编辑没保存), 再添加一个JDBC Request,设置其Query Typerollback(至关于编辑后撤销),再次查询,仍然没有更改。

若是把JDBC connection configuration中的自动提交为true,执行更改,增长或删除操做后,查询数据更改,但一旦事物被提交就没法rollback

Autocommit(false)Autocommit(true):

JDBC connection configuration中的自动提交为truefalse,是设置系统参数的默认值。添加一个JDBC Request,设置其Query Type Autocommittruefalse后(至关于修改系统参数),再进行对数据库的增长、删除、修改操做。

Edit:必须是对上述之一的结果的引用, 为使用正则表达式的操做。

2Parameter values:表示咱们要添加的数据,须要不一样数据添加可使用参数化

Parameter types为上面须要输入数据的类型,与上面的一一对应

Parameter valuesParameter types:成对出现,且sql语句中有多少个?,这里就必须有多少对参数键值对,假设sql语句为select * from ZMYW_USER  where ID=?,那么能够设置Parameter values${id}Parameter typesVARCHAR 

(3)Variable names:变量名称,为数据库的字段名称,有多个字段返回时,可使用逗号隔开,用于存放select操做返回的查询结果 

Result variable name:用于存放select操做返回的查询结果集。

3.扩展:

(1) 当选择了"Prepared select statement"”Prepared update statement "Callable statement"的类型时,每一个链接的语句缓存使用 JDBC 请求。在默认状况下将存储每一个链接高达 100 Prepared Statements,这可能会影响您的数据库 (打开的游标)。这能够经过定义"jdbc sampler.nullmarker"属性更改。

(2)在实际的项目中,至少有2种类型的JDBC请求须要关注:select语句和存储过程。前者反应了select语句是否高效,以及表的索引等是否须要优化;后者则是反应存储过程的算法是否高效。它们若是效率低下,必然会带来响应上的不尽如人意。对于这两种请求,JDBC请求的配置略有区别。


1Query TypeSelect Statement时,对应执行代码为:stmt = conn.createStatement(); 

ResultSet rs = null; 

rs = stmt.executeQuery(sql); 

return getStringFromResultSet(rs).getBytes(ENCODING); 

2Query TypeCallable Statement时,对应执行代码为:CallableStatement cstmt = getCallableStatement(conn); 

int out[]=setArguments(cstmt); 

boolean hasResultSet = cstmt.execute(); 

String sb = resultSetsToString(cstmt,hasResultSet, out); 

return sb.getBytes(ENCODING); 

3Query TypeUpdate Statement时,对应执行代码为:stmt = conn.createStatement(); 

stmt.executeUpdate(sql); 

int updateCount = stmt.getUpdateCount(); 

String results = updateCount + " updates"; 

return results.getBytes(ENCODING); 

4Query TypePrepared Select Statement时,对应执行代码为:PreparedStatement pstmt = getPreparedStatement(conn); 

setArguments(pstmt); 

ResultSet rs = null; 

rs = pstmt.executeQuery(); 

return getStringFromResultSet(rs).getBytes(ENCODING); 

5Query TypePrepared Update Statement时,对应执行代码为:

PreparedStatement pstmt = getPreparedStatement(conn); 

setArguments(pstmt); 

pstmt.executeUpdate(); 

String sb = resultSetsToString(pstmt,false,null); 

return sb.getBytes(ENCODING); 

6Query TypeRollback时,对应执行代码为:

   conn.rollback(); 

return ROLLBACK.getBytes(ENCODING); 

7Query TypeCommit时,对应执行代码为:

conn.commit(); 

return COMMIT.getBytes(ENCODING); 

8Query TypeAutoCommit(false)时,对应执行代码为:conn.setAutoCommit(false); 

return AUTOCOMMIT_FALSE.getBytes(ENCODING); 

9Query TypeAutoCommit(true)时,对应执行代码为:

conn.setAutoCommit(true); 

return AUTOCOMMIT_TRUE.getBytes(ENCODING); 

10)其它状况直接抛异常:throw new UnsupportedOperationException("Unexpected query type: "+_queryType);

相关文章
相关标签/搜索