import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
//预处理方式
public class preperSTest {
public static void main(String[] args) throws SQLException {
read("刘章","蔷薇");
}
private static void read(String name,String flower) throws SQLException {
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
// 创建连接
conn = JdbcUtils.getConnection();
String sql = "insert into boys (name,flower) values (?,?)";
ps = conn.prepareStatement(sql);
// 代替占位符
ps.setString(1, name);
ps.setString(2, flower);
int i = ps.executeUpdate();
System.out.println(i);
} finally {
JdbcUtils.release(rs, ps, conn);
}
}
}
————————————————
版权声明:本文为CSDN博主「明明如月学长」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/w605283073/article/details/46572487