需要加載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','[email protected]','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 {
stmt.close();
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}//end of action
public int end() throws Throwable {
}//end of end
1
<code><br></code>
<code></code>
本文轉自 知止内明 51CTO部落格,原文連結:http://blog.51cto.com/357712148/1894654,如需轉載請自行聯系原作者