如何用在LoadRunner下用JDBC连接linux下的mysql
折腾了一天。可以连接本地的mysql连接mysql会出来如下报错:
-----------------------------------------------------------------
虚拟用户脚本已于 : 2016/5/31 18:43:45 启动
正在开始操作 vuser_init。
错误: System.err: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server. Error
System.err: at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) Error
System.err: at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) Error
System.err: at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) Error
System.err: at java.lang.reflect.Constructor.newInstance(Constructor.java:513) Error
System.err: at com.mysql.jdbc.Util.handleNewInstance(Util.java:404) Error
错误: System.err: at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:988) Error
System.err: at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:341) Error
System.err: at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2251) Error
System.err: at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2284) Error
System.err: at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2083) Error
System.err: at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:806) Error
System.err: at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47) Error
System.err: at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) Error
System.err: at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) Error
System.err: at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) Error
System.err: at java.lang.reflect.Constructor.newInstance(Constructor.java:513) Error
System.err: at com.mysql.jdbc.Util.handleNewInstance(Util.java:404) Error
System.err: at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:410) Error
System.err: at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:328) Error
System.err: at java.sql.DriverManager.getConnection(DriverManager.java:582) Error
System.err: at java.sql.DriverManager.getConnection(DriverManager.java:207) Error
System.err: at Actions.init(Actions.java:19) Error
错误: System.err: Caused by: java.net.ConnectException: Connection timed out: connect Error
System.err: at java.net.PlainSocketImpl.socketConnect(Native Method) Error
System.err: at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351) Error
System.err: at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213) Error
System.err: at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200) Error
System.err: at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366) Error
System.err: at java.net.Socket.connect(Socket.java:529) Error
System.err: at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:211) Error
System.err: at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:300) Error
System.err: ... 15 more Error
错误: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
错误: at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:404)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:988)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:341)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2251)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2284)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2083)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:806)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:404)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:410)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:328)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
从操作调用了中止。
帖出连接脚本:
------------------------------------------------------------------------------------------------
import lrapi.lr;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class Actions
{
private Connection conn=null;
private Statement stmt=null;
private ResultSet rs=null;
private String server="192.168.1.121:3306";//数据库地址
private String dataBase="practice";//数据库名
private String username="root";//用户名
private String passworkd="123123";//密码
public int init() throws Throwable
{
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn=DriverManager.getConnection("jdbc:mysql://"+server+"/"+dataBase+"?user="+username+"&password="+passworkd);
stmt=conn.createStatement();
return 0;
}
public int action() throws Throwable
{
rs=stmt.executeQuery("select * from SC");
while(rs.next())
{
lr.error_message(rs.getString("Sid")); //打印出查询的结果
}
return 0;
}
public int end() throws Throwable
{
stmt.close();
conn.close();
return 0;
}
}
我也在学怎么将qtp 与mysql 联通
页:
[1]