package com.song.testjdbc.lesson2;
import com.song.testjdbc.lesson2.utils.JdbcUtils;
import java.sql.*;
public class zhuru {
public static void main(String[] args) {
Connection connection=null;
PreparedStatement preparedStatement = null;
ResultSet resultSet = null;
try {
connection = JdbcUtils.getConnection();
//区别 使用问号占位符代替参数
String sql = "INSERT into tb_user(userid,username,userPwd,userAge) VALUES (?,?,?,?)";
preparedStatement = connection.prepareCall(sql);//预编译
//手动赋值
preparedStatement.setInt(1,4444);
preparedStatement.setString(2,"陈欢");
preparedStatement.setString(3,"13");
preparedStatement.setString(4,"13");
int i = preparedStatement.executeUpdate();
if (i>0){
System.out.println("执行成功");
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}