package cn.itheima.jdbc.test;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import org.junit.Test;
import cn.itheima.jdbc.JDBCUtils_V1;
import cn.itheima.jdbc.JDBCUtils_V2;
import cn.itheima.jdbc.JDBCUtils_V3;
/**
* 测试工具类
*
* @author XING
*
*/
public class TestUtils {
/**
* 根据id更新用户信息方法
*/
@Test
public void tesUpdateById(){
Connection conn = null;
PreparedStatement pstmt = null;
try {
//1.获取连接
conn = JDBCUtils_V3.getConnection();
//2.编写SQL语句
String sql = "update tbl_user set upassword=? where uid=?";
//3.获取执行SQL语句对象
pstmt = conn.prepareStatement(sql);
//4.设置参数
pstmt.setString(1, "888");
pstmt.setInt(2, 1);
//5.执行删除操作
int row = pstmt.executeUpdate();
if(row>0){
System.out.println("更新成功");
}else{
System.out.println("更新失败");
}
} catch (Exception e) {
throw new RuntimeException(e);
}finally{
//6.释放资源
JDBCUtils_V3.release(conn, pstmt, null);
}
}