Mysql查询分页
说明:这是一个实例,其中有些东西是可以抽取出来的,作为一个公共的方法,可是实现复用
public class TestService {
public static TestService test=null;
public static TestService getTestService(){
if(test==null){
test=new TestService();
}
return test;
}
public List getTest(int pageNow ,int pageSize){
String sql="select count(*) from user";
Connection conn=DB.getConn();
Statement stmt=DB.getStmt(conn);
ResultSet rs=DB.getRs(stmt, sql);
int num;
try {
rs.next();
num=rs.getInt(1);
} catch (SQLException e) {
e.printStackTrace();
}
sql="select *from user limit "+(pageNow*pageSize-pageSize)+","+pageSize;
PreparedStatement pstmt=DB.getPstmt(conn, sql);
List list=new ArrayList<Test>();
try {
rs=pstmt.executeQuery(sql);
while(rs.next()){
Test t=new Test();
t.setId(rs.getInt("id"));
t.setAge(rs.getInt("age"));
t.setName(rs.getString("name"));
list.add(t);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return list;
}
}
相关文档:
自增长类型增加
1.如果dbms是MsSql,则选定表后,database-> edit current dbms-> 出现DBMS properties对话框,选择General页,左侧的树选择SQL 2000-> Profile-> Column-> Extended Attributes 下面的ExtIdentityIncrement是步进 ......
mysql 可以通过子查询得到要删除的记录条件,然后通过子查询得结果匹配要删除的记录。但是 mysql 不能直接删除子查询表中的数据,必须通过一个临时表来解决。例如:
delete from t_transaction where exists
(select d.* from t_ti_category a,t_category b,t_ ......
当mysql数据库为GBK编号,.net程序使用默认编码(UTF-8),向mysql中插入数据容易产生乱码。解决办法是在连接字符串加入Charset=gbk:
MySqlConnection myConnection = new MySqlConnection("Database=test2;Data Source=localhost;User Id=root;Password=ikmbikmb;Charset=gbk"); ......
转自http://blog.csdn.net/ytz_linuxer/archive/2009/07/04/4321259.aspx
以版本phpMyAdmin-2.6.1.tar.gz为例
先解压phpMyAdmin-2.6.1.tar.gz到/usr/local/apache2/htdocs,
得到文件夹phpMyAdmin-2.6.1,将其重命名为phpmyadmin,(这样在以后的操作中将会变的简便)。
  ......
作者:Dirk (dirk.ye AT gmail.com)
Url:http://dirk.pdx.cn
日期:2004/12/08
首先,目前在产品环境可用的MySQL版本(指4.0.x和4.1.x)中,只有InnoDB引擎才允许使用外键,所以,我们的数据表必须使用
InnoDB引擎。
下面,我们先创建以下测试用数据库
表:
CREATE TABLE `roottb` (
`id` INT(11) UNSIGNED AU ......