尝试写一下JDBC
1.注册驱动
Class.forName("com.mysql.cj.jdbc.Driver);
2.获取链接
DriverManager.getConnection("jdbc:mysql://localhost:3306/pulao_dragontoll's_home","root","114514"); (.var)
3.编写sql语句,并把动态结果用 ?代替
String sql="insert into users(account,password,nickname) values (?,?,?)";
4.创建PreparedStatement,并且传入sql语句结果
connection.preparedStatement(sql).var;
5.占位符赋值
preparedStatement.setObject(1,"ceshi");
preparedStatement.setObject(2,"ceshi");
preparedStatement.setObject(3,"lovely_carrot");
6.发送sql语句
int rows=preparedStatement.executeUpdate();
7.测试结果
8.释放空间
preparedStatement.close();
connection.close();
标签:总结,语句,preparedStatement,setObject,14,mysql,2023,sql,close From: https://www.cnblogs.com/zhanshuang/p/17700880.html