需要加载jdk1.6
/*
* LoadRunner Java script. (Build: _build_number_)
*
* Script Description:
*
*/
import lrapi.lr;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class Actions
{
public int init() throws Throwable {
return 0;
}//end of init
public int action() throws Throwable {
String url = "jdbc:mysql://localhost:3306/school?useUnicode=true&characterEncoding=UTF-8";
String username = "root";
String password = "";
Connection conn = null;
PreparedStatement stmt = null;
ResultSet rs = null;
int idhao;
try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection(url, username, password);
// String sql =
// "insert into Students values (8,'admin',12,'m','admin@123.net','abc');";
String sql = "insert into Students values (?,?,?,?,?,?);";
stmt = conn.prepareStatement(sql);
//注意:下标从1开始。
stmt.setInt(1, 2); //?整数暂时不知道怎么参数
stmt.setString(2, "<name>"); //参数
stmt.setInt(3, 24); //没有参数成功
stmt.setString(4, "<sex>"); //参数
stmt.setString(5, "<email>"); //参数
stmt.setString(6, "<address>"); //参数
int result = stmt.executeUpdate();
if(result>0)
{
System.out.println("插入成功!");
}
else
{
System.out.println("插入失败!");
}
} catch (Exception ex) {
ex.printStackTrace();
} finally {
try {
stmt.close();
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return 0;
}//end of action
public int end() throws Throwable {
return 0;
}//end of end
}