今天写了个 MySQL 分页的 javabean,是用 MySQL 里的 LIMIT 来实现的.
int Offset; // 记录偏移量
int MaxLine; // 记录每页显示记录数
String FilePath;
dbClass db; // object of dbclass
//constructer do nothing
//********读取记录***************
String query_part, os;
// 截取 " FROM " 以后的 query 语句
// 计算偏移量
// 获取文件名
Query = query;
// 计算总的记录条数
if(Offset >= MaxLine)
// public: connection parameters
String DBDriver = "org.gjt.mm.MySQL.Driver";
// public: constructor to load driver and connect db
ResultSet rs = null;
this.rs = rs;
return rs;
}
// perform a query without records returned
public boolean executeUpdate(String sql)
{
try
{
stmt = con.createStatement();
stmt.executeUpdate(sql);
return true;
}
catch(SQLException e)
{
System.out.print("Update:"+e.getMessage());
return false;
}
}
// return the num of columns
public int getColumns()
{
int columns = 0;
try
{
this.resultsMeta = this.rs.getMetaData();
columns = this.resultsMeta.getColumnCount();
}
catch (SQLException e) {}
return columns;
}
// return the num of rows
public int getRows()
{
return this.rows;
}
public String getDBName() {
return this.dbName;
}
}