回顾PreparedStament和Session

mac2022-06-30  25

PreparedStament sql预处理对象

PreparedStament pst =null;

String sql =" SELECT `userName`,`password` FROM `news_user` WHERE `userName` = ? AND `password` = ? " ; Object[] pars ={user.getName(),user.getPwd()};

pst = connection.prepareStatement(sql);

for(int i =0;i<pars.length;i++;){

pst.setObject(i+1,parms[i])    //?占位符的初始下标为1,所以为了对应,i+1

}

int count = pst.excuteUpdate();  //执行失败返回-1  成功 有多少条返回多少条

 

Session

HttpSession session = request.getSession(); //创建session对象

session.setAttribute("name",name);//session赋值

${name} jsp前台页面获取

转载于:https://www.cnblogs.com/jiayiblog/p/11014046.html

最新回复(0)