Java中实现对表中多个字段的模糊查询(Oracle)

	public UserVO fuzzyQuery(String keyword) {
		UserVO user=null;
		ResultSet rs = null;
		PreparedStatement prep = null;
		try {
			String sql="select * from users where status=1 and (username like '%'||'"+keyword+"'||'%' or passwd like '%'||'"+keyword+"'||'%' or power like '%'||'"+keyword+"'||'%' or name like '%'||'"+keyword+"'||'%' or sex like '%'||'"+keyword+"'||'%' or birthday like '%'||'"+keyword+"'||'%' or email like '%'||'"+keyword+"'||'%')";
			prep=conn.prepareStatement(sql);
			rs=prep.executeQuery();
			while(rs.next()) {
				user = new UserVO();
				user.setUsername(rs.getString("username"));
				user.setPasswd(rs.getString("passwd"));
				user.setPower(rs.getInt("power"));
				user.setName(rs.getString("name"));
				user.setSex(rs.getString("sex"));
				user.setBirthday(rs.getDate("birthday"));
				user.setEmail(rs.getString("email"));
				user.setStatus(rs.getInt("status"));
				System.out.println(user.getUsername()+" "
				+Md5Utils.md5Jdk(user.getPasswd())+" "  /**md5Jdk(String passwd)为封装在Md5Utils中的MD5加密算法实现,自定义*/
				+user.getPower()+" "
				+user.getName()+" "
				+user.getSex()+" "
				+user.getBirthday()+" "
				+user.getEmail()+" "
				+user.getStatus()
				);
				
			}
			
		}catch (Exception e) {
			System.out.println("模糊查询---daoimpl 出错"+e.getMessage());
			e.printStackTrace();
		
		}
		return user;
		
	}

 

你可能感兴趣的:(oracle,Java)