用javabean来实现MySQL的分页显示

发布时间:2015-09-10 00:00
来源:未知 我要投稿

今天写了个 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;

}

}

声明:本站(华域联盟www.cnhackhy.com)所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。