简单的连接数据库的java程序,方便临时使用:
import java.sql.*; import java.io.*; import java.sql.DriverManager; import java.sql.Connection; import java.sql.SQLException; public class perftest { public static void main(String arr[]) throws Exception { System.out.println( "start" ); DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver()); Connection conn = DriverManager.getConnection ("jdbc:oracle:thin:@LLWP0JKR8KXJJ6J:1521:muphy", "eoda", "foo"); Integer iters = new Integer(arr[0]); Integer commitCnt = new Integer(arr[1]); conn.setAutoCommit( false ); doInsert(conn, 1, 1); Statement stmt = conn.createStatement(); stmt.execute("begin dbms_monitor.session_trace_enable(waits=>true); end;"); doInsert(conn, iters.intValue(), commitCnt.intValue()); conn.close(); } static void doInserts(Connection con, int count, int commitCount ) throws Exception { PreparedStatement ps = con.prepareStatement ("insert into test " + "(id, code, descr, insert_user, insert_date)" + " values (?,?,?, user, sysdate)"); int rowcnt = 0; int committed = 0; for (int i = 0; i < count; i++ ) { ps.setInt(1,i); ps.setString(2,"PS - code" + i); ps.setString(3,"PS - desc" + i); ps.executeUpdate(); rowcnt++; if ( rowcnt == commitCount ) { con.commit(); rowcnt = 0; committed++; } } con.commit(); System.out.println ("pstatement rows/commitcnt = " + count + " / " + committed ); } }