对于一个比较复杂的sql语句
createStatement加不加参数的需要时间到底是多少呢,
st = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
开始时间:Sat Jun 28 15:33:47 CST 2014
结束时间:Sat Jun 28 15:33:53 CST 2014 ps:7秒左右,数据大概120条
st = conn.createStatement();
开始时间:Sat Jun 28 15:36:21 CST 2014
结束时间:Sat Jun 28 15:36:22 CST 2014
开始时间:Sat Jun 28 15:36:30 CST 2014
结束时间:Sat Jun 28 15:36:30 CST 2014 ps:1秒不到,数据120条
看到这里,我果断去掉了参数。
下面是引用网上的文章,比较详细,大家可以根据自己的需要使用参数。
1、createStatement();
2、createStatement(int resultSetType, int resultSetConcurrency)
3、createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability)
其中resultSetType可选值是:
1、ResultSet.TYPE_FORWARD_ON
2、ResultSet.TYPE_SCROLL_INSENSITIVE 在ResultSet中可以随心所欲的先前向后移动游标,
3、ResultSet.TYPE_SCROLL_SENSITIVE 在ResultSet中可以随心所欲的先前向后移动游标,同时ResultSet的值有所改变的时候,他可以得到改变后的最新的值
其中resultSetConcurrency可选值是:
1、ResultSet.CONCUR_READ_ON
2、ResultSet.CONCUR_UPDATABLE 在ResultSet中的数据记录可以任意修改,然后更新会数据库
其中resultSetHoldability可选值是:
1、ResultSet.HOLD_CURSORS_OVER_COMMIT 表示修改提交时,不关闭ResultSet的游标
2、ResultSet.CLOSE_CURSORS_AT_COMMIT 表示修改提交时,关闭ResultSet的游标
对于查询操作第一种初始化方法createStatement(),
相当于第二种方法的createStatement(ResultSet.TYPE_FORWARD_ON
相当于第三种方法的createStatement(ResultSet.TYPE_FORWARD_ON
还有别人常常说的:Statement stmt = Conn.createStatement(1004,1007);
其实这些参数名称都对应一个整数值:
TYPE_FORWARD_ON
TYPE_SCROLL_INSENSITIVE=1004
TYPE_SCROLL_SENSITIVE=1005
CONCUR_READ_ON
CONCUR_UPDATABLE=1008