JavaWeb基础--(模糊搜索自动填充)

web脚本代码:

  
		

请填写如下信息:

输入查询内容:

Service层代码:

public List findWord(String word) throws SQLException {
		String[] strs = word.split("'");
		StringBuffer sb = new StringBuffer();
		for (String str : strs) {
			sb.append(str);
		}
		FindWordDao findWord = new FindWordDao();
		List wordList = findWord.findByWord(new String (sb));
		return wordList;
	}

dao层代码:

public List findByWord(String wrod) throws SQLException {
		List wordList = new ArrayList();
		Connection conn = JdbcUtils.getConnection();
		Statement st = null;
		ResultSet rs = null;
		if(conn != null){
			String sql = "select * from UT_E_Stock where name like '%"+wrod+"%' ";
			System.out.println(sql);
			st = conn.createStatement();
			rs = st.executeQuery(sql);
			while(rs.next()){
				String name = rs.getString("Name");
				wordList.add(name);
			}
		}
		return wordList;
	}

运行实例:
JavaWeb基础--(模糊搜索自动填充)_第1张图片

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