You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '5 * from forum where id>0 order by id desc' at line 1
解决方案 »
- ireport问题:为什么显示不出粗体和斜体呢?
- 很着急,java报错信息,高手帮帮忙呀
- eclipse数据源连接池提示Missing application web.xml, using defaults ***错误
- 各位高手,求助,急!提交插入SQL的都是NULL!
- 关于恢复数据库SQL2000出现的问题!!高手帮忙解决下 谢谢
- 在java下在常用的AJAX有哪些
- 求助,网站数据分析埋点技术
- onclick裡如何寫 "/editlisttwo.do?actn=listtwo"
- 用jsp做了个计数器,请问以下BufferedReader读的数据源count.txt文件的存放路径?
- SpringMV项目部署问题
- 几种输出流输出图片的大小不同
- jsp读取CSV文件如何替换csv文件?
把这代码贴出来啊。
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;import domain.ForumInfoVo;
import util.ConnectionDB;
import util.PageList;public class ForumDAO {
Connection conn=null;
private PageList pl=null;
//构造方法,获得数据库连接与分页公共类
public ForumDAO() throws ClassNotFoundException{
conn=(new ConnectionDB()).getConnection();
pl=new PageList();
}
//获得分页数目
public Integer pageSize(){
int maxRow= pl.pageSize("forum");
int pages = maxRow / 5;
if (maxRow % 5 > 0) {
pages = pages + 1;
return pages;
}
return pages;
}
//保存帖子
public void save(ForumInfoVo forum) throws SQLException{
try {
String sql = "insert into forum (title,content,ip,createtime,author_id,authorname) values(?,?,?,?,?,?)";
PreparedStatement psmt = conn.prepareStatement(sql);
psmt.setString(1,forum.getTitle());
psmt.setString(2,forum.getContent());
psmt.setString(3,forum.getIp());
psmt.setString(4,forum.getCreatetime());
psmt.setInt(5, forum.getAuthor_id());
psmt.setString(6, forum.getAuthorname());
psmt.execute();
conn.commit();
} catch (Exception e) {
conn.rollback();
e.printStackTrace();
}
}
//查询所有帖子
public List<ForumInfoVo> findAll(int currentePage ) throws SQLException{
try {
ResultSet rs=pl.pageList(5,"forum",currentePage,"desc","id");
rs.beforeFirst();
List<ForumInfoVo> list=new ArrayList<ForumInfoVo>();
while (rs.next()){
ForumInfoVo f=new ForumInfoVo();
f.setId(rs.getInt("id"));
f.setTitle(rs.getString("title"));
f.setIp(rs.getString("ip"));
f.setCreatetime(rs.getString("createtime"));
f.setAuthor_id(rs.getInt("author_id"));
f.setAuthorname(rs.getString("authorname"));
f.setCountback(rs.getInt("countback"));
list.add(f);
}
return list;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
//查看单个帖子
public ForumInfoVo findById(int id) throws SQLException{
try {
String sql = "select * from forum where id=?";
PreparedStatement psmt = conn.prepareStatement(sql);
psmt.setInt(1, id);
ResultSet rs=psmt.executeQuery();
rs.next();
ForumInfoVo f=new ForumInfoVo();
f.setId(rs.getInt("id"));
f.setTitle(rs.getString("title"));
f.setContent(rs.getString("content"));
f.setIp(rs.getString("ip"));
f.setCreatetime(rs.getString("createtime"));
f.setAuthor_id(rs.getInt("author_id"));
f.setAuthorname(rs.getString("authorname"));
f.setCountback(rs.getInt("countback"));
conn.commit();
rs.close();
return f;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
//计算回帖数目
public Integer countBack(int forum_id) throws SQLException{
try {
String sql = "select countback from forum where id=?";
PreparedStatement psmt = conn.prepareStatement(sql);
psmt.setInt(1,forum_id);
ResultSet rs=psmt.executeQuery();
int coutback;
if(rs.next()){
coutback=rs.getInt("countback");
return coutback;
}
} catch (Exception e) {
//添加总回帖数错误
conn.rollback();
e.printStackTrace();
}
return 0;
}
//增加回帖数目
public Integer addCountBack(int countback,int forum_id) throws SQLException{
try {
String sql = "update forum set countback=? where id=?";
PreparedStatement psmt = conn.prepareStatement(sql);
psmt.setInt(1,countback+1);
psmt.setInt(2, forum_id);
psmt.executeUpdate();
} catch (Exception e) {
conn.rollback();
e.printStackTrace();
}
return 0;
}
//减少回帖数目
public Integer removeCountBack(int countback,int forum_id) throws SQLException{
try {
String sql = "update forum set countback=? where id=?";
PreparedStatement psmt = conn.prepareStatement(sql);
psmt.setInt(1,countback-1);
psmt.setInt(2, forum_id);
psmt.executeUpdate();
} catch (Exception e) {
conn.rollback();
e.printStackTrace();
}
return 0;
}
//删除帖子
public boolean delete(int id) throws SQLException{
try {
String delreform="delete reforum where forum_id=?";
PreparedStatement psmt1 = conn.prepareStatement(delreform);
psmt1.setInt(1, id);
psmt1.executeUpdate();
String sql = "delete forum where id=?";
PreparedStatement psmt2 = conn.prepareStatement(sql);
psmt2.setInt(1, id);
int b=psmt2.executeUpdate();
conn.commit();
if(b!=0){
return true;
}else{
return false;
}
} catch (Exception e) {
conn.rollback();
e.printStackTrace();
}
return false;
}
}