Javabean:
package form;
import java.sql.Date;
public class topicForm {
private int rq;
private String content;
private String title;
private String xq;
private Date submitime;
private String forumname;
private int forumid;
private String author;
private String submittime;
public String getSubmittime() {
return submittime;
}
public void setSubmittime(String submittime) {
this.submittime = submittime;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public int getRq() {
return rq;
}
public void setRq(int rq) {
this.rq = rq;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getXq() {
return xq;
}
public void setXq(String xq) {
this.xq = xq;
}
public Date getSubmitime() {
return submitime;
}
public void setSubmitime(Date submitime) {
this.submitime = submitime;
}
public String getForumname() {
return forumname;
}
public void setForumname(String forumname) {
this.forumname = forumname;
}
public int getForumid() {
return forumid;
}
public void setForumid(int forumid) {
this.forumid = forumid;
}
}
action:
public class ActicleAction extends ActionSupport{
private static final long serialVersionUID = 1L;
private topicForm t;
public topicForm getT() {
return t;
}
public void setT(topicForm t) {
this.t = t;
}
public String execute() throws Exception{
HttpServletRequest request=ServletActionContext.getRequest();
ArrayList<topicForm> l=new ArrayList<topicForm>();
l=f.getForum(“f”);
request.getSession().setAttribute("listcontent",l);
return SUCCESS;
}
jsp:
<s:iterator value="#session.listcontent" status="s" id="item">
<td><s:property value="#s.rq" /></td>
<tr style="<s:if test="#it.odd"> </s:if>" >
<td style="width: 357px;"><a href="Reply.jsp"> <s:property value="#item.content" /></a></td>
<td><s:property value="#item.rq" /></td>
<td><s:property value="#item.rq" /></td>
<td><s:property value="#item.submittime" /></td>
<td><s:property value="#item.forumname" /></td>
</tr>
</s:iterator>
数据库查询:
public ArrayList<topicForm> getForum(String name) throws Exception{
ArrayList<topicForm> l=new ArrayList<topicForm>();
topicForm t=new topicForm();
String a=null;
String b=null;
int c=0;
String d=null;
ResultSet rs=null;
Connection conn=DBConnection.getConnection();
String sql="select content,rq,submittime,forumname from tb_topic where author='"+name+"' ";
PreparedStatement pt=conn.prepareStatement(sql);
rs=pt.executeQuery();
int i=0;
while(rs.next()){
t.setContent(rs.getString("content"));
t.setForumname(rs.getString("forumname"));
t.setRq(rs.getInt("rq"));
t.setSubmittime(rs.getString("submittime"));
l.add(i,t);
i++;
}
rs.close();
pt.close();
conn.close();
return l;
}
显示:
显示为什么只是很多条同样的信息?
4 个解决方案
#1
没人吗,自己顶!d=====( ̄▽ ̄*)b
#2
快点来人啊
#3
#4
使用preparedstatement字符串不是动态创建的。下面是一个动态创建字符串的例子:
stringsql = "select * from people p where p.i = "+id; 就像你写的那样。
应该像下面的例子一样:
stringsql = "select * from people p where p.id = ? and p.name = ?";
preparedstatement ps = connection.preparestatement(sql);
ps.setint(1,id);
ps.setstring(2,name);
resultset rs = ps.executequery();
要不直接用statement。不要用preparedStaement
stringsql = "select * from people p where p.i = "+id; 就像你写的那样。
应该像下面的例子一样:
stringsql = "select * from people p where p.id = ? and p.name = ?";
preparedstatement ps = connection.preparestatement(sql);
ps.setint(1,id);
ps.setstring(2,name);
resultset rs = ps.executequery();
要不直接用statement。不要用preparedStaement
#1
没人吗,自己顶!d=====( ̄▽ ̄*)b
#2
快点来人啊
#3
#4
使用preparedstatement字符串不是动态创建的。下面是一个动态创建字符串的例子:
stringsql = "select * from people p where p.i = "+id; 就像你写的那样。
应该像下面的例子一样:
stringsql = "select * from people p where p.id = ? and p.name = ?";
preparedstatement ps = connection.preparestatement(sql);
ps.setint(1,id);
ps.setstring(2,name);
resultset rs = ps.executequery();
要不直接用statement。不要用preparedStaement
stringsql = "select * from people p where p.i = "+id; 就像你写的那样。
应该像下面的例子一样:
stringsql = "select * from people p where p.id = ? and p.name = ?";
preparedstatement ps = connection.preparestatement(sql);
ps.setint(1,id);
ps.setstring(2,name);
resultset rs = ps.executequery();
要不直接用statement。不要用preparedStaement