新手求助!JSP+JavaBean动态显示
用Java Bean连接数据库做动态的页面吗?就是把放在数据库里的新闻的标题从数据库中读出动态显示!
比如我的数据库的字段有ID; Name; Title; Author; Time;有15条记录!如何动态显示!用JSP+JavaBean做!!那位给各例子!谢谢!!
------解决方案--------------------bean
package jbean;
import java.sql.*;
import java.util.*;
public class jobsBean {
jbean.conBean objconBean = jbean.conBean.newInstanse();
private int job_id;
private String job_desc;
private int min;
private int max;
Connection con = null;
private int curPage=1;
private int maxPage;
private int rowsInPage=5;
public jobsBean() {
this.init();
}
public void setJob_id(int job_id) {
this.job_id = job_id;
}
public void setJob_desc(String job_desc) {
this.job_desc = job_desc;
}
public void setMin(int min) {
this.min = min;
}
public void setMax(int max) {
this.max = max;
}
public void setCurPage(int curPage) {
this.curPage = curPage;
}
public void setMaxPage(int maxPage) {
this.maxPage = maxPage;
}
public int getJob_id() {
return job_id;
}
public String getJob_desc() {
return job_desc;
}
public int getMin() {
return min;
}
public int getMax() {
return max;
}
public int getCurPage() {
return curPage;
}
public int getMaxPage() {
return maxPage;
}
public ArrayList query(String page)
{
ArrayList objAL = new ArrayList();
try
{
int pageNum = Integer.parseInt(page);
jobsBean objBean = new jobsBean();
con = objconBean.getConn();
Statement sm = con.createStatement();
ResultSet rs = sm.executeQuery( "select top "+pageNum*this.rowsInPage+ " * from jobs ");
int i=1;
while(rs.next())
{
if(i> (pageNum-1)*this.rowsInPage){
objBean = new jobsBean();
objBean.setJob_id(rs.getInt(1));
objBean.setJob_desc(rs.getString(2));
objBean.setMin(rs.getInt(3));
objBean.setMax(rs.getInt(4));
objAL.add(objBean);
}
i++;
}
objBean.setCurPage(pageNum);
rs.close();
sm.close();
}
catch(Exception ex)
{
System.out.println(ex);
}
finally
{
try {
if(con!=null)
con.close();
}
catch (Exception ex) {
System.out.println(ex);
}
}
return objAL;
}
public void init()
{
int result=0;
try
{
con = objconBean.getConn();
Statement sm = con.createStatement();
ResultSet rs = sm.executeQuery( "select count(*) from jobs ");
while(rs.next())
{
result=rs.getInt(1);
}
rs.close();
sm.close();
}
catch(Exception ex)
{
System.out.println(ex);
}
finally
{
try {
if(con!=null)
con.close();
}
catch (Exception ex) {
System.out.println(ex);
}
}
if(result%this.