com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException异常求助
异常代码如下图:


分页代码如下:
package dao;
import java.sql.Connection;
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;
}
}
相关推荐
Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: ….. this is incompatible with sq
1、写在开头 标题之前我想说一下Linux的mysql真的实在是太坑了。太坑了。总是会出现这样那样的你想不到的问题。崩溃了。首先来罗列一下我遇到过的一些问题吧。 1、大小写敏感 2、连接数超过系统最大连接数 3、Can’t connect to local MySQL server through socket ‘/Data/mydata/mysql.sock’ socket文件目录不对应导致的问题 4、今天要说的就是 没有打开only_full_group_by Cause:com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorExcepti
正确解决com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException异常的有效解决方法
正确解决com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException异常的有效解决方法
bitronix 连接 MySQL 出现MySQLSyntaxErrorException 的解决方法
主要介绍了bitronix 连接 MySQL 出现MySQLSyntaxErrorException 的解决方法的相关资料,需要的朋友可以参考下
jdbc中常见异常原因以及解决方法
jdbc中常见异常原因以及解决方法 jdbc中常见异常原因以及解决方法
mysql_jdbc连接数据库-错误提示.pdf
mysql_jdbc连接数据库-错误提示.pdf


Web 开发
