日志输出有问题?如何解决?
java vuser中的java脚本是:import java.io.*;
import lrapi.lr;
import java.sql.*;
public class Actions
{
int sum = 0;
public int init() throws Throwable {
return 0;
}//end of init
public int action() throws Throwable {
try{
String sqldriver = "sun.jdbc.odbc.JdbcOdbcDriver";
Class.forName(sqldriver);
System.out.println("driver is OK !");
String url ="jdbc:odbc:Test_LR"; //建立数据连接,连数据库
String user = "sa"; //数据库用户名
String password = "111111";//数据库密码
String sel = "select * from UserInfo"; //执行的查询语句
Connection conn = DriverManager.getConnection(url,user,password);
System.out.println("conn succes");
//lr.start_transaction("select");
Statement sta = conn.createStatement();
ResultSet rs = sta.executeQuery(sel);
System.out.print("\t"+"UserName"+"\t"+"PassWord"+"\n"); //函数输出表的各个字段名字
while(rs.next())
{
System.out.print("\t"+rs.getString(1));
System.out.print("\t"+rs.getString(2)+"\n"); sum = sum + 1 ;
}
rs.close();
sta.close();
conn.close();
}catch(Exception e){
e.printStackTrace();
System.out.println("Test Failed");
}
lr.message("Sum = "+sum);
//lr.end_transaction("select", lr.AUTO);
return 0;
}//end of action
public int end() throws Throwable {
return 0;
}//end of end
}
可是输出的日志为:
Ending action vuser_init.
Running Vuser...
Starting iteration 1.
Starting action Actions.
System.out: driver is OK ! Notify:
System.out: conn succes Notify:
Sum = 10
Ending action Actions.
Ending iteration 1.
Ending Vuser...
Starting action vuser_end.
Ending action vuser_end.
Vuser Terminated.
回放日志中没有查询结果显示!!!???
为什么??? System.out:driver is OK ! System.out: conn succes
这都能输出来 为何到了 ResultSet rs = sta.executeQuery(sel);
就不输出了? 如果是这样的脚步就:
String sqldriver = "sun.jdbc.odbc.JdbcOdbcDriver";
Class.forName(sqldriver);
System.out.println("driver is OK !");
String url ="jdbc:odbc:Test_LR"; //建立数据连接,连数据库
String sel = "select * from UserInfo"; //执行的查询语句
Connection conn = DriverManager.getConnection(url,"sa","111111");
//lr.start_transaction("select");
Statement sta = conn.createStatement();
ResultSet rs = sta.executeQuery(sel);
System.out.print("\t"+"UserName"+"\t"+"PassWord"+"\n"); //函数输出表的各个字段名字
while(rs.next())
{
System.out.print("\t"+rs.getString(1));
System.out.print("\t"+rs.getString(2)+"\n");
sum = sum + 1 ;
}
System.out.println("conn succes");
rs.close();
sta.close();
conn.close();
}catch(Exception e){
e.printStackTrace();
System.out.println("Test Failed");
}
lr.message("Sum = "+sum);
//lr.end_transaction("select", lr.AUTO);
return 0;
}//end of action
日志就是
Virtual User Script started
Starting action vuser_init.
Ending action vuser_init.
Running Vuser...
Starting iteration 1.
Starting action Actions.
System.out: driver is OK ! Notify:
System.out: UserName PassWord
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
0 0
conn succes Notify:
Sum = 10
Ending action Actions.
Ending iteration 1.
Ending Vuser...
Starting action vuser_end.
Ending action vuser_end.
Vuser Terminated.
这是为什么! 如果是这样的脚步就:
String sqldriver = "sun.jdbc.odbc.JdbcOdbcDriver";
Class.forName(sqldriver);
System.out.println("driver is OK !");
String url ="jdbc:odbc:Test_LR"; //建立数据连接,连数据库
String sel = "select * from UserInfo"; //执行的查询语句
Connection conn = DriverManager.getConnection(url,"sa","111111");
//lr.start_transaction("select");
Statement sta = conn.createStatement();
ResultSet rs = sta.executeQuery(sel);
System.out.print("\t"+"UserName"+"\t"+"PassWord"+"\n"); //函数输出表的各个字段名字
while(rs.next())
{
System.out.print("\t"+rs.getString(1));
System.out.print("\t"+rs.getString(2)+"\n");
sum = sum + 1 ;
}
System.out.println("conn succes");
rs.close();
sta.close();
conn.close();
}catch(Exception e){
e.printStackTrace();
System.out.println("Test Failed");
}
lr.message("Sum = "+sum);
//lr.end_transaction("select", lr.AUTO);
return 0;
}//end of action
日志就是
Virtual User Script started
Starting action vuser_init.
Ending action vuser_init.
Running Vuser...
Starting iteration 1.
Starting action Actions.
System.out: driver is OK ! Notify:
System.out: UserName PassWord
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
0 0
conn succes Notify:
Sum = 10
Ending action Actions.
Ending iteration 1.
Ending Vuser...
Starting action vuser_end.
Ending action vuser_end.
Vuser Terminated.
这是为什么! 难道是LR不支持“System.out.print()"!!!! 基本上是这样的用lr.output_message来代替
页:
[1]