其他分享
首页 > 其他分享> > preparedStatement插入

preparedStatement插入

作者:互联网

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();
}
}
}

搜索

复制

标签:preparedStatement,setString,插入,connection,testjdbc,sql,null
来源: https://www.cnblogs.com/wutonga/p/16353033.html