.......String sql = "select * from Contact where cName like '%" + context
+ "%'";
sql = sql + "or cAddress like '%" + context + "%'";
sql = sql + "or cEmail like '%" + context + "%'";
sql = sql + "or cPhone like '%" + context + "%'";
ResultSet rs = db.executeQuery(sql);
xmlBuffer.append("<contexts>");
try {
while (rs.next()) {
// 生成xml文档
xmlBuffer.append("<context>");
xmlBuffer.append("<ID>" + rs.getString(1) + "</ID>");
xmlBuffer.append("<cName>" + rs.getString(2) + "</cName>");
xmlBuffer.append("<cAddress>" + rs.getString(3) + "</cAddress>");
xmlBuffer.append("<cEmail>" + rs.getString(5) + "</cEmail>");
xmlBuffer.append("<cPhone>" + rs.getString(4) + "</cPhone>");
xmlBuffer.append("</context>");
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
xmlBuffer.append("</contexts>");
System.out.println("发送给客户端数据:" + xmlBuffer.toString());
........
这是我写一个AJAX小程序时服务端Servlet中的一小段代码...