java根据姓名检索信息功能怎么做

DAO:publicMessagesearchMessage(Stringname)throwsSQLException;DAOIMPL:publicMessagesea... DAO:

public Message searchMessage(String name)throws SQLException;
DAOIMPL:
public Message searchMessage(String name) throws SQLException {
String sql="select * from message where name=?";
Message message=new Message();
PreparedStatement pstmt=null;
ResultSet rs=null;
Connection conn=ConnDB.getConnection();
try {
pstmt=conn.prepareStatement(sql);
pstmt.setString(1, name);
rs=pstmt.executeQuery();
if(rs.next()){
message.setMessageid(rs.getRow());
message.setName(rs.getString("name"));
message.setQq(rs.getInt("qq"));
message.setTitle(rs.getString("title"));
message.setContent(rs.getString("content"));
message.setReply(rs.getString("reply"));
message.setTime(rs.getString("time"));

}
rs.close();
pstmt.close();
} catch (SQLException e) {
e.printStackTrace();
}

return message;
}
servlet;(servlet要怎么写)
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
PrintWriter out = response.getWriter();
method = Integer.parseInt(request.getParameter("method"));
if(method==1){
search(request, response);
}
}
private void search(HttpServletRequest request,HttpServletResponse response)
throws IOException{
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
PrintWriter out=response.getWriter();
Message message=new Message();
jsp:
<form name="searchForm" action="SearchServlet?method=1"method="post">
姓名:<input name="name" type="text">
<input name="search"type="submit"value="检索留言">
展开
 我来答
学无只静
2013-11-27 · 超过10用户采纳过TA的回答
知道答主
回答量:74
采纳率:0%
帮助的人:23万
展开全部
servlet中:
String name =request.getPapameter("name");//接收页面信息
DAOIMPL d=new DAOIMPL();
ArrayList list=new ArrayList();

list=D.searchMessage(name);
reqeust.setAttribute("list",list);
request.getRequestDispatcher("/info.jsp").forward(request, response);
更多追问追答
追问

list=D.searchMessage(name);这句会提示。错误。

想问下。如果我这样写。还有哪里要改吗

追答
兄弟,你这报错是因为不能用int型接收,你查询出来返回的是个Massage,你应该用这个接收,如果想用int,那你应该在impl中返回一个int型的值
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式