Code example for PreparedStatement

Methods: executeQuery, setString

0
		User user=null;
 
		try { 
			conn = super.getConnection();// µÃµ½Óï¾ä¶ÔÏó
			stmt = conn.prepareStatement(sql);
			stmt.setString(1, name);
			stmt.setString(2, password);
			rs = stmt.executeQuery();// Ö´ÐÐÓï¾ä
 
			// ´¦Àí½á¹û 
			if (rs.next()) {
				user=new User();
				user.setUsid(rs.getInt("usid"));
				user.setUname(rs.getString("uname"));
				user.setUpwd(rs.getString("upwd"));
			} 
			// ´¦ÀíÒì³£ 
		} catch (SQLException e) {
			e.printStackTrace();
		} finally { 
			super.closeAll(conn, stmt, rs);
		} 
		return user;
	} 
 
}