jsp使用javabean连接数据库 分页显示
showCourse.java文件
package Show;
import java.sql.*;
import com.sun.rowset.*;
public class showCourse{
int pageSize=10;
int pageAll=0;
int showPage=1;
StringBuffer pr;
CachedRowSetImpl rowSet;
String driverName="com.mysql.jdbc.Driver";
String userName="";
String userPasswd="";
String dbName="";
String tableName="";
String i[]=new String[100];
int j=0;
public showCourse(){
pr=new StringBuffer();
try{
Class.forName(driverName).newInstance();
}catch(Exception e){
e.printStackTrace();}
}
public void setPage(int size){
pageSize=size;
j=0;
String url="jdbc:mysql://localhost/"+dbName+"?user="+userName+"&password="+userPasswd;
try{
Connection conn=DriverManager.getConnection(url);
DatabaseMetaData met=conn.getMetaData();
ResultSet rs1=met.getColumns(null,null,tableName,null);
int k=0;
while(rs1.next()){
j++;
i[k]=rs1.getString(3);
k++;
}
Statement sql=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
ResultSet rs=sql.executeQuery("SELECT * FROM "+tableName);
rowSet =new CachedRowSetImpl();
rowSet.populate(rs);
conn.close();
rowSet.last();
int m=rowSet.getRow();
int n=pageSize;
pageAll=((m%n)==0)?(m/n):(m/n+1);
}catch(Exception e1){}
}
public int getPageSize(){
return pageSize;
}
public int getPageAll(){
return pageAll;
}
public void setShowPage(int n){
showPage=n;
}
public int getShowPage(){
return showPage;
}
public StringBuffer getPR(){
if(showPage>pageAll)
showPage=1;
if(showPage<=0)
showPage=pageAll;
pr=show(showPage);
return pr;
}
public StringBuffer show(int page){
StringBuffer str=new StringBuffer();
str.append("<table border=1>");
str.append("<tr>");
for(int t=0;t<j;t++){
str.append("<th>"+i[t]+"</th>");
}
str.append("</tr>");
try{
rowSet.absolute((page-1)*pageSize+1);
for(int t=1;t<=pageSize;t++){
str.append("<tr>");
for(int k=1;k<=j;k++){
str.append("<td>"+rowSet.getString(k)+"</td>");
}
str.append("</tr>");
rowSet.next();
}
}catch(SQLException e2){}
str.append("</table>");
return str;
}
public void setDatabaseName(String s){
dbName=s.trim();
}
public String getDatabaseName(){
return dbName;
}
public void setTableName(String s){
tableName=s.trim();
}
public String getTableName(){
return tableName;
}
public void setPassword(String s){
userPasswd=s.trim();
}
public void setUserName(String s){
userName=s.trim();
}
public String getUserName(){
return userName;
}
}
show.jsp文件
<%@ page contentType="text/html; charset=gb2312" %>
<%@ page import="Show.showCourse" %>
<%@ page import="java.sql.*" %>
<jsp:useBean id="look" class="Show.showCourse" scope="session"/>
<jsp:setProperty name="look" property="dbName" value="lxylxj"/>
<jsp:setProperty name="look" property="tableName" value="course"/>
<jsp:setProperty name="look" property="userName" value="root"/>
<jsp:setProperty name="look" property="userPasswd" value="mysql"/>
<jsp:setProperty name="look" property="pageSize" value="5"/>
<html>
<body>
共<jsp:getProperty name="look" property="pageAll"/>页 <br> <br>
每页最多<jsp:getProperty name="look" property="pageSize"/>条记录 <br> <br>
<jsp:setProperty name="look" property="showPage"/>
<jsp:getProperty name="look" property="pr"/> <br> <br>
单击“前一页”或“后一页”按钮查看记录(当前显示第 <jsp:getProperty name="look" property="showPage"/> 页)
<table>
<tr><td><form action="">
<input type=hidden name="showPage" value="<%=look.getShowPage()-1 %>">
<input type=submit name="g" value="前一页">
</form>
</td>
<td><form action="">
<input type=hidden name="showPage" value="<%=look.getShowPage()-1 %>">
<input type=submit name="g" value="后一页">
</form>
</td>
<td><form action="">
输入页码:<input type=text name="showPage" size=5 >
<input type =submit name="g" value="提交">
</form>
</td>
</tr>
</table>
</body>
</html>
提示错误:Cannot find any information on property 'pr' in a bean of type 'Show.showCourse'
这是为什么啊,实在解决不了,求大神 JSP javabean 分页 数据库
[解决办法]
public StringBuffer getPr(){
r小写。。