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;
}
}
相关文档:
最近在做一个小项目,开发环境:数据库mysql5.0,服务器Tomcat5.5。项目打成war部署在tomcat上之后,通过应用进行查询操作,如果操作过于频繁,后台会抛如下异常:
javax.servlet.ServletException: Hibernate operation: Cannot open connection; uncategorized SQLException for SQL [???]; SQL state [08S01]; error co ......
删除rpm包
rpm -e mysql-embedded-5.1.39-4.fc12.i686 --nodeps
安装rpm包
rpm -vih MySQL-server-community-5.1.37-0.rhel5.i386.rpm
查询已安装的rpm包
rpm -qa | grep MySQL
启动mysql
mysql(没有密码的情况)
&nbs ......
关键字: mysql grant
本文实例,运行于 MySQL 5.0 及以上版本。
MySQL 赋予用户权限命令的简单格式可概括为:
grant 权限 on 数据库对象 to 用户
一、grant 普通数据用户,查询、插入、更新、删除 数据库中所有表数据的权利。
grant select on testdb.* to common_user@'%'
grant insert on testdb.* to common_user ......
转自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 ......