com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 '-8,8' at line 1
表信息:-- Table "updateanddownload" DDLCREATE TABLE `updateanddownload` ( `filename` char(255) NOT NULL, `resourcesize` int(11) DEFAULT NULL, `resourcetype` char(20) DEFAULT NULL, `updator` char(20) DEFAULT NULL, `updateDate` char(30) DEFAULT NULL, `downtime` int(11) DEFAULT NULL, `resourcename` char(255) DEFAULT NULL, `redescription` char(255) DEFAULT NULL, `tag` char(255) DEFAULT NULL, `path` char(100) NOT NULL, `ID` int(255) NOT NULL AUTO_INCREMENT, PRIMARY KEY (`ID`)) ENGINE=InnoDB AUTO_INCREMENT=31 DEFAULT CHARSET=utf8;
sql语句:String sql = "select * from updateanddownload limit "+countOfPage*(corruntPage-1)+","+countOfPage+"";
FilePaging.java类情况:
public List<File> fenye(int corruntPage,int countOfPage) throws ClassNotFoundException, SQLException { List<File> FileList1 = new ArrayList<File>(); String sql = "select * from updateanddownload limit "+countOfPage*(corruntPage-1)+","+countOfPage+""; pre = FilePaging.getConnection().prepareStatement(sql); res = pre.executeQuery(); while (res.next()) { File file = new File(); file.setFilename(res.getString("filename")); file.setResourcesize(res.getInt("resourcesize")); file.setResourcetype(res.getString("resourcetype")); file.setUpdator(res.getString("updator")); file.setUpdateDate(res.getString("updateDate")); file.setDowntime(res.getInt("downtime")); file.setResourcename(res.getString("resourcename")); file.setRedescription(res.getString("redescription")); file.setTag(res.getString("tag")); file.setPath(res.getString("path")); file.setID(res.getInt("ID")); FileList1.add(file); } return FileList1; }
public int allRecord() throws ClassNotFoundException, SQLException
{
int record = 0;
String sql = "select *from updateanddownload";
pre = FilePaging.getConnection().prepareStatement(sql);
res = pre.executeQuery();
res.last();
record = res.getRow();
return record;
}
public int sumPageCount(int onePageRecord) throws ClassNotFoundException, SQLException
{
int sumPageCount=0;
int record =this.allRecord();
if(record%onePageRecord==0)
{
sumPageCount= record/onePageRecord;
}
else
{
sumPageCount= record/onePageRecord+1;
}
return sumPageCount;
}
download.jsp页面:<% int onePageRecord=8; int allRecord=0; int currentPage=0; int sumPage = 0; FilePaging page1 = new FilePaging(); allRecord = page1.allRecord(); sumPage = page1.sumPageCount(onePageRecord);
List<File> fileli =page1.fenye(currentPage,onePageRecord); request.setAttribute("filelist1",fileli);
%>
表信息:-- Table "updateanddownload" DDLCREATE TABLE `updateanddownload` ( `filename` char(255) NOT NULL, `resourcesize` int(11) DEFAULT NULL, `resourcetype` char(20) DEFAULT NULL, `updator` char(20) DEFAULT NULL, `updateDate` char(30) DEFAULT NULL, `downtime` int(11) DEFAULT NULL, `resourcename` char(255) DEFAULT NULL, `redescription` char(255) DEFAULT NULL, `tag` char(255) DEFAULT NULL, `path` char(100) NOT NULL, `ID` int(255) NOT NULL AUTO_INCREMENT, PRIMARY KEY (`ID`)) ENGINE=InnoDB AUTO_INCREMENT=31 DEFAULT CHARSET=utf8;
sql语句:String sql = "select * from updateanddownload limit "+countOfPage*(corruntPage-1)+","+countOfPage+"";
FilePaging.java类情况:
public List<File> fenye(int corruntPage,int countOfPage) throws ClassNotFoundException, SQLException { List<File> FileList1 = new ArrayList<File>(); String sql = "select * from updateanddownload limit "+countOfPage*(corruntPage-1)+","+countOfPage+""; pre = FilePaging.getConnection().prepareStatement(sql); res = pre.executeQuery(); while (res.next()) { File file = new File(); file.setFilename(res.getString("filename")); file.setResourcesize(res.getInt("resourcesize")); file.setResourcetype(res.getString("resourcetype")); file.setUpdator(res.getString("updator")); file.setUpdateDate(res.getString("updateDate")); file.setDowntime(res.getInt("downtime")); file.setResourcename(res.getString("resourcename")); file.setRedescription(res.getString("redescription")); file.setTag(res.getString("tag")); file.setPath(res.getString("path")); file.setID(res.getInt("ID")); FileList1.add(file); } return FileList1; }
public int allRecord() throws ClassNotFoundException, SQLException
{
int record = 0;
String sql = "select *from updateanddownload";
pre = FilePaging.getConnection().prepareStatement(sql);
res = pre.executeQuery();
res.last();
record = res.getRow();
return record;
}
public int sumPageCount(int onePageRecord) throws ClassNotFoundException, SQLException
{
int sumPageCount=0;
int record =this.allRecord();
if(record%onePageRecord==0)
{
sumPageCount= record/onePageRecord;
}
else
{
sumPageCount= record/onePageRecord+1;
}
return sumPageCount;
}
download.jsp页面:<% int onePageRecord=8; int allRecord=0; int currentPage=0; int sumPage = 0; FilePaging page1 = new FilePaging(); allRecord = page1.allRecord(); sumPage = page1.sumPageCount(onePageRecord);
List<File> fileli =page1.fenye(currentPage,onePageRecord); request.setAttribute("filelist1",fileli);
%>
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货