?? listviewbeanbo.java
字號:
//這是一定義操作留言板的方法;
package cn.rludrea.model;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
public class listViewBeanBO {
//定義一些變量[];
private ResultSet rs=null;
private Connection ct=null;
private PreparedStatement ps=null;
/**
* 這是一個返回留言板總共有多少條記錄的方法;
* @author rludrea
* @return rowCount(int)
*/
public int getCount()
{
int rowCount=0;
try
{
ct=new ConnDB().getConn();
ps=ct.prepareStatement("select count(*) from listview");
rs=ps.executeQuery();
if(rs.next())
{
rowCount=rs.getInt(1);
}
}catch(Exception e)
{
e.printStackTrace();
}
finally
{
new close().Close();
}
return rowCount;
}
/**
* 返回總共有多少頁;
* @author rludrea
* @param pageSize
* @return int :返回一個總共有多少頁;
*/
public int getPageCount(int pageSize)
{
int pageCount=0;
int rowCount=0;
try{
ct=new ConnDB().getConn();
ps=ct.prepareStatement("select count(*) from listview");
rs=ps.executeQuery();
if(rs.next())
{
rowCount=rs.getInt(1);
}
if(rowCount%pageSize==0)
{
pageCount=rowCount/pageSize;
}
else
{
pageCount=rowCount/pageSize+1;
}
}catch(Exception e)
{
e.printStackTrace();
}finally
{
new close().Close();
}
return pageCount;
}
/**
* 這是一個顯示留言的方法;
* @author rludrea
* @param pageSize (int)
* @param pageNow (int)
* @return al(ArrayList)返回一個留言板的數據集;
*/
public ArrayList getListByPage(int pageSize,int pageNow)
{
ArrayList al=new ArrayList();
try
{
ct=new ConnDB().getConn();
ps=ct.prepareStatement("select top "+pageSize+" * from listview where listId not in(select top "+(pageNow-1)*pageSize+" listId from listview) order by listId desc");
rs=ps.executeQuery();
while(rs.next())
{
listViewBean lvb=new listViewBean();
lvb.setListId(rs.getInt(1));
lvb.setListEmail(rs.getString(2));
lvb.setListName(rs.getString(3));
lvb.setListContent(rs.getString(4));
lvb.setDatetime(rs.getDate(5));
al.add(lvb);
}
}catch(Exception e)
{
e.printStackTrace();
}
finally
{
new close().Close();
}
return al;
}
/**
* 這是個留言板添加的方法;
* @author rludrea
* @param listEmail(String)
* @param listName(String)
* @param listContent(String)
* @return b(boolean)返回一個布爾值,表示是否添加成功;
*/
public boolean addList(String listEmail,String listName,String listContent)
{
boolean b=false;
try
{
ct=new ConnDB().getConn();
ps=ct.prepareStatement("insert into listview (listEmail,listName,listContent)values('"+listEmail+"','"+listName+"','"+listContent+"')");
// ps.setString(1, listEmail);
// ps.setString(2, listName);
// ps.setString(3, listContent);
int index=ps.executeUpdate();
if(index==1)
{
b=true;
}
}catch(Exception e)
{
e.printStackTrace();
}
finally
{
new close().Close();
}
return b;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -