1、 禁止自动提交:
在默认情况下,程序执行的任何sql 语句都是自动提交的
向一个表中插入2000条记录,
自动提交所用的时间  11666毫秒
禁止自动提交(显示提交) 3450毫秒

2、 批处理:
多用批处理,减少操作数据库次数。

(1)、禁止自动提交
setAutoCommit(false);
(2)、准备一个语句对象
PreparedStatement myPrepStatement = myConnection.prepareStatement(“insert into test_tab(value) values(?)”;
(3)、将语句添加进批中
addBatch();
(4)、执行这批语句
executeBatch();
(5)、提交执行的语句
myConnection.commit();

Oracle新的改进后的批处理:(JDBC2.0以上支持)
   只能对OraclePreparedStatement对象进行处理,其中的sql语句在5-30个是最优化的)
   改进的地方是,可以预设批大小,SQL 语句就会自动添加进批中。

(1)、禁止提交
(2)、设置批值
myoracleConnection.setDefaultExecuteBatch(10);
(3)、对SQL语句进行批处理
for (int count = 0;count<20;count++){
myOraclePrepStatement.setInt(1,count);
int rowsInserted = myOraclePrepStatement.executeUpdate();
}
注:还可以强制执行int rowsInserted = myOraclePrepStatement.sendBatch();

3、 行预获取
默认情况下,结果集获取的行数是10,对大多数程序都是合适的,但是,如果要获取的行非常多,那么可以增加获取尺寸以便进一步提高程序性能。
通常采用Oracle行预获取,而不用标用行预获取

标准行预获取
Statement myStatement = myConnection.CreateStatement();
myStatement.setFetchSize(20);
从数据库取2000条记录
当设为1 1642毫秒
10 161毫秒
20 91毫秒 Oracle行预获取
OracleStatement myOracleStatement = (OracleSTatement) myConntion.CreateStatement();
myOracleStatement.setRowPrefetch(20); 当设为1  1532毫秒
11 140毫秒
21 80毫秒

4、 定义结果集类型及长度
预先定义结果集列的Java类型,可以节省判断结果集类型往返。
当查询发送到数据库时,会有一次往返判断结果集应该使用的Java类型。

((OracleStatement) myStatement).defineColumnType(1,java.sql.Types.INTEGER);

5、 语句缓存
使用缓存的语句,通常可以将准备语句的时间减少一半,同时还要以避免使用结果集时创建新的游标。
两种类型: 
隐式语句缓存 
前后两次使用的语句字符串完全一样。
  显示语缓存

((OracleStatement)myPrepStatement).closeWithKey(“myCachedStatement”);

6、 数据类型定义
定义成与SQL一样的数据类型。
7、 变量名定义规则
变量大小写一至,SQL 语句字符串大小写一至。

>>>等值关联
select a.id,a.title,b.columnid
from articleinfo a,articlecolumn b
where a.id=b.articlei; >>>外关联
select a.id,a.title,b.columnid
from articleinfo a,articlecolumn b
where a.id=b.articlei(+) and b.articleid not null; >>>内关联
select a.id,a.title,b.columnid
from articleinfo a,articlecolumn b
where b.articlei(+)=a.id and b.articleid not null; >>>等值关联
select a.id,a.title
from articleinfo a,articlecolumn b
where a.id=b.articleid; >>>IN关联
Select a.id,a.title from articleinfo a
Where a.id in(select articleid from articlecolumn b); >>>等值关联 (40%)
select a.id,a.title
from articleinfo a
where exists(select b.articleid from articlecolumn b
where a.id=b.articleid); >>>创建函数索引
select a.id,a.title
from articleinfo
where trunc(entertime)>=sysdate-30; create index fun_trunc_entertime on articleinfo(trunc(entertime)) >>>显示使用某个索引
select /*+ articleinfo(fun_trunc_entertime) */ id from articleinfo
where trunc(entertime)>=sysdate-30; >>>Where子句中的条件顺序
范围越小越靠后
select a.id,b.columnid from articleinfo a,articlecolumn b
where a.id=b.articleid(+) and b.articleid is not null and b.columnid>=353454564564576 and b.columnid<234345344565676;
• Nested Loops (NL) Join
• Sort-Merge Join
• Hash Join (not available with the RBO)
• Cluster Join

最新文章

  1. ASP.NET Core 中文文档 第三章 原理(17)为你的服务器选择合适版本的.NET框架
  2. iOS 浅谈:深.浅拷贝与copy.strong
  3. DIY PIXHAWK APM等飞控用的PPM转接板
  4. Java中的异常
  5. 8、JavaScript深入浅出——数据类型
  6. (转)Position定位:relative | absolute
  7. asp.net中使用swfupload上传大文件
  8. C#打开指定目录,并将焦点放在指定文件上。相对路径(程序起动的目录)
  9. [ACM] 最短路算法整理(bellman_ford , SPFA , floyed , dijkstra 思想,步骤及模板)
  10. Ubuntu 搭建NDK环境
  11. Ext布局篇
  12. org.hibernate.exception.GenericJDBCException: Could not open connection
  13. spring-data-jpa中save不触发数据库insert语句的问题
  14. Golang微服务:Micro限流、熔断
  15. Mad Libs游戏,华氏与摄氏转换
  16. mac mysql5.7.17修改root初始密码(知道初始密码)
  17. Link Between SAP SD, MM &amp; FI
  18. Hadoop生态的配置
  19. 洛谷 P2622 关灯问题II(状压DP入门题)
  20. 自定制Centos7.3系统镜像(ISO)

热门文章

  1. 基于Jenkins自动构建系统开发
  2. 【Linux学习】Linux系统管理1—进程管理
  3. 激光SLAM
  4. Flutter实战视频-移动电商-32.列表页_小类高亮交互效果制作
  5. jQuery 如何获取ASP.NET服务器控件的值
  6. 让App飞久一点
  7. Sping中使用Junit进行测试
  8. [Xcode 实际操作]二、视图与手势-(7)UIView视图的渐变填充
  9. 关于idea中使用lamb表达式报错:ambda expressions are not supported at this language level
  10. scrapy框架中选择器的用法