2018-03-09

批处理:

预处理语句对象    PRoparedStatement

String sql = " delete from (表格名) where id = ? " ;

ProparedStatement pstmt = conn.prepareStatement(sql);

如果删除10条数据,与数据库交互10次

for(int id : ids){

pstmt.setInt( 1 , id );

//将操作添加到语句列表中

pstmt.addBatch();

//pstmt.exectreUpdate();

//一次性缓存一组数据

在语句对象中,维护了一个语句列表

}

//一次性执行一组操作

pstmt.executeBatch();

addBatch(),填充语句列表

executeBatch(),执行语句列表

clearBatch(),.清楚语句列表

可滚动结果集

ResultSet rs = pstmt.execureQuery();

rs . next ();

boolean next() ; 从前往后滚动

boolean absolute() ; 将结果集指针绝对定位

boolean previous() ; 从后往前滚动

JDBC分页查询(Mysql)

    分页

    两种分页方式:

* 内存分页

        查询所有数据,储存在内存中

* 数据库端分页(常用)

        查询需要的数据(与数据库多次交互)

数据库(mysql)端分页:

limit关键字,mysql专用分页查询关键字

select id, title from 表格 limit ?  , 5 ; 

int perPage = 5;

int page = 4;

int begin = (page-1) * perPage;

你可能感兴趣的:(2018-03-09)