2019-06-13

String sql="select*from user where name=? and pwd=?";

PrepareStatement pstm=conn.prepareStatement(sql);

pstm.setString(1,"name");

pstm.setInt(2."pwd");

ResultSet rs=  pstm.executeQuery();


String sql="select*from user where name=? and pwd=?";

User u=new User();

String name=u.setName("zhangsan");

int pwd=u.setPwd(123);

Object[] obj={name,pwd};

PrepareStatement pstm=conn.prepareStatement(sql);

ResultSet rs=null;

for(int i =0;i

pstm.setObject(i+1,obj[i]);

}

rs=pstm.executeQuery(); //查询返回ResultSet

}


String sql="delete from user where id=? ";

User u=new User();

int id=u.setid(123);

Object[] obj={id};

PrepareStatement pstm=conn.prepareStatement(sql);


for(int i =0;i

pstm.setObject(i+1,obj[i]);

}

int i=pstm.executeUpdate(); //增删改 返回int

}



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

session.setSession("name","张三");//赋值

session.getSession(name);//取值

你可能感兴趣的:(2019-06-13)