Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0

路人呵呵 2012-10-24 03:28:30

package com.yong.java;

/* create table test
( id number,
code varchar2(20),
descr varchar2(20),
insert_user varchar2(30),
insert_date date
)
*/
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.Statement;


public class Perftest {

public static void main (String arr[]) throws Exception
{
DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
Connection con = DriverManager.getConnection("jdbc:oracle:thin:@192.168.130.129:1521:yongdb","scott", "tiger");

Integer iters = new Integer(arr[0]); ////出错行
Integer commitCnt = new Integer(arr[1]);

con.setAutoCommit(false);

doInserts( con, 1, 1 );

Statement stmt = (Statement) con.createStatement ();
stmt.execute( "begin dbms_monitor.session_trace_enable(waits=>true); end;" );

doInserts( con, iters.intValue(), commitCnt.intValue() );

con.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 );
}
}


Integer iters = new Integer(arr[0]); ////出错行

求大神指导
版权归 Oracle 9i&10g&11g 编程艺术.pdf 361页所有


...全文
376 4 打赏 收藏 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
路人呵呵 2012-10-24
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 的回复:]

引用 2 楼 的回复:
在MyEclipse 10 编辑代码界面 右键 run as 过去的


方法没错,估计是没设置正确或成功,你再重新试试看。

另外,前面加一句话:
System.out.println(arr.length);
[/Quote]

懂了
Integer iters = 数字;
Integer commitCnt = 数字;
原文说要 Now we’ll run this code repeatedly with different inputs and review the resulting TKPROF file
手动输入数字后可以运行
谢谢大神指点
MiceRice 2012-10-24
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 的回复:]
在MyEclipse 10 编辑代码界面 右键 run as 过去的
[/Quote]

方法没错,估计是没设置正确或成功,你再重新试试看。

另外,前面加一句话:
System.out.println(arr.length);
路人呵呵 2012-10-24
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]

你启动该程序的时候,是怎么指定参数的?

如果不知道怎么指定参数,就直接把:
Integer iters = new Integer(arr[0]); ////出错行
Integer commitCnt = new Integer(arr[1]);
修改为:
Integer iters = 数字;
Integer commitCnt = 数字;
[/Quote]
在MyEclipse 10 编辑代码界面 右键 run as 过去的
MiceRice 2012-10-24
  • 打赏
  • 举报
回复
你启动该程序的时候,是怎么指定参数的?

如果不知道怎么指定参数,就直接把:
Integer iters = new Integer(arr[0]); ////出错行
Integer commitCnt = new Integer(arr[1]);
修改为:
Integer iters = 数字;
Integer commitCnt = 数字;

62,620

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧