其他分享
首页 > 其他分享> > PrepareStatement的步骤

PrepareStatement的步骤

作者:互联网

(1)导入jar并加载驱动
Class.forName("com.mysql.jdbc.Driver");
(2)获取连接
connection=DriverManager.getConnection("jdbc:mysql://localhost:3306/mytest","root","root");
(3)写sql语句---?
String sql="select * from user where uname=? and password=?";
(4)生成PrepareStatement
PreparedStatement prepareStatement=connection.prepareStatement(sql);
(5)设置参数
prepareStatement.setString(1, username);
prepareStatement.setString(2, usermm);
(6)执行sql操作
prepareStatement.executeUpdate();//增删改,返回影响行数
ResultSet resultSet=prepareStatement.executeQuery();//查询
(7)关闭资源---后开的先关

标签:jdbc,PrepareStatement,步骤,setString,sql,---,prepareStatement,mysql
来源: https://www.cnblogs.com/daxixixy/p/14743469.html