[20250125]如何编译与运行FetchSize.java.txt --//https://connor-mcdonald.com/2025/01/17/jdbc-the-fetchsize-and-staying-up-to-date/ --//看了里面的链接,测试看看。 $ cat FetchSize.java import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; public class FetchSize { public static void main(String[] args) throws SQLException { try (Connection con = DriverManager.getConnection("jdbc:oracle:thin:scott/book@//127.0.0.1/book01p")) { // try (Connection con = DriverManager.getConnection("jdbc:oracle:thin:MYUSER/MYPASS@//MYHOST/MYDB?defaultRowPrefetch=1000")) { try (Statement stmt = con.createStatement()) { System.out.println("Creating test table"); try { stmt.execute("drop table tmp_fetch_demo purge"); } catch (SQLException ignored) { } stmt.execute("create table tmp_fetch_demo as select a.* from all_objects a, ( select 1 from dual connect by level <= 10) "); // stmt.execute(""" // create table tmp_fetch_demo as // select a.* // from all_objects a, (select 1 from dual connect by level <= 50)"""); System.out.println("Done."); // If you want to trace this // // stmt.execute("alter session set tracefile_identifier = FETCH"); // stmt.execute("alter session set sql_trace = true"); int newFetchSize; if (args.length > 0 && (newFetchSize = Integer.parseInt(args[0])) > 0) { System.out.println("Setting JDBC Statement default fetch size to " + newFetchSize); stmt.setFetchSize(newFetchSize); } else if (stmt.getFetchSize() == 10) { System.out.println("Keeping default JDBC Statement default fetch size (" + stmt.getFetchSize() + ")"); } else { System.out.println("JDBC Statement default fetch size set to " + stmt.getFetchSize() + " using connection string parameter"); } try (ResultSet rs = stmt.executeQuery("select object_id, object_name from tmp_fetch_demo")) { System.out.println("Querying all rows"); long startTime = System.nanoTime(); long cnt = 0; while (rs.next()) { int v1 = rs.getInt(1); String v2 = rs.getString(2); cnt++; } System.out.println("ResultSet fetch size " + rs.getFetchSize()); long duration = (System.nanoTime() - startTime) / 1000000L; long tp = (long) ((double) cnt / duration * 1000d); System.out.printf("Rows fetched %d%nDuration %d ms%nThroughput %d rows/sec%n", cnt, duration, tp); } } } } } --//已经根据要求修改连接数据库的字符串。仅仅减少select 1 from dual connect by level <= 10,不然建立的表有点大。 --//这样建立的表为120M。 $ javac FetchSize.java --//编译通过。 $ java FetchSize 0 Error: Could not find or load main class FetchSize $ java FetchSize 100 Error: Could not find or load main class FetchSize --//不熟悉java,视乎提示找不到对应的class FetchSize。 $ java -cp . FetchSize 100 Exception in thread "main" java.sql.SQLException: No suitable driver found for jdbc:oracle:thin:scott/book@//127.0.0.1/book01p at java.sql.DriverManager.getConnection(DriverManager.java:689) at java.sql.DriverManager.getConnection(DriverManager.java:270) at FetchSize.main(FetchSize.java:9) --//jdbc没有找到。 $ java -cp /u01/app/oracle/product/21.0.0/dbhome_1/jdbc/lib/ojdbc8.jar:. FetchSize 100 Creating test table Done. Setting JDBC Statement default fetch size to 100 Querying all rows ResultSet fetch size 100 Rows fetched 699150 Duration 1066 ms Throughput 655863 rows/sec $ java -cp /u01/app/oracle/product/21.0.0/dbhome_1/jdbc/lib/ojdbc8.jar:. FetchSize 0 Creating test table Done. Keeping default JDBC Statement default fetch size (10) Querying all rows ResultSet fetch size 10 Rows fetched 699150 Duration 3471 ms Throughput 201426 rows/sec $ java -cp /u01/app/oracle/product/21.0.0/dbhome_1/jdbc/lib/ojdbc8.jar:. FetchSize Creating test table Done. Keeping default JDBC Statement default fetch size (10) Querying all rows ResultSet fetch size 10 Rows fetched 699150 Duration 3563 ms Throughput 196225 rows/sec --//设置0的缺省等于10。两者时间相差3倍。 --//不加参数如何执行,不是很清楚,那位知道。 --//应该设置某个环境变量就可以执行,不熟悉java。
[20250125]如何编译与运行FetchSize.java.txt
来源:这里教程网
时间:2026-03-03 21:23:15
作者:
编辑推荐:
- [20250125]如何编译与运行FetchSize.java.txt03-03
- oracle 19CRAC打补丁到19.2603-03
- hyper v win10,hyper v win10的实操流程,hyper-v批量管理工具的使用指南03-03
- hyper-v设置,hyper-v设置的实操流程,hyper-v批量管理工具的使用指南03-03
- hyper v 系统,hyper v 系统的实操流程,hyper-v批量管理工具的使用指南03-03
- ADG端连接显示ORA-2800003-03
- OGG DDL触发器引发的故障系列(二)03-03
- Oracle使用psqlODBC访问PostgreSQL03-03
下一篇:
相关推荐
-
雷神推出 MIX PRO II 迷你主机:基于 Ultra 200H,玻璃上盖 + ARGB 灯效
2 月 9 日消息,雷神 (THUNDEROBOT) 现已宣布推出基于英
-
制造商 Musnap 推出彩色墨水屏电纸书 Ocean C:支持手写笔、第三方安卓应用
2 月 10 日消息,制造商 Musnap 现已在海外推出一款 Oce
热文推荐
- hyper v win10,hyper v win10的实操流程,hyper-v批量管理工具的使用指南
- hyper-v设置,hyper-v设置的实操流程,hyper-v批量管理工具的使用指南
- hyper v 系统,hyper v 系统的实操流程,hyper-v批量管理工具的使用指南
- ADG端连接显示ORA-28000
ADG端连接显示ORA-28000
26-03-03 - OGG DDL触发器引发的故障系列(二)
OGG DDL触发器引发的故障系列(二)
26-03-03 - 湖南家具月球表面床,一键开启太空梦境
湖南家具月球表面床,一键开启太空梦境
26-03-03 - Oracle添加ASM磁盘故障
Oracle添加ASM磁盘故障
26-03-03 - 一车封神的小米汽车,2025还能躺赢吗
一车封神的小米汽车,2025还能躺赢吗
26-03-03 - 原以为微软、亚马逊、阿里云云计算大局已定!没想到有这四大变数
原以为微软、亚马逊、阿里云云计算大局已定!没想到有这四大变数
26-03-03 - hyper.js,hyper.js是什么,hyper-v批量管理工具的使用教程
