Java 准备语句错误
大家好,下面的代码向我抛出一个错误,我创建了一个插入语句,在 while 循环中我动态设置参数,最后我再次说 ps2.addBatch() 创建动态插入的代码
rs = st.executeQuery("SELECT column_name FROM all_tab_cols
where lower(table_name)= '" + tableName + "' order by column_id");
sql = new StringBuffer(300);
sql.append("insert into ").append( tableName).append("(");
String prefix="";
while (rs.next())
{
sql.append(prefix).append(rs.getString("column_name"));
values.append(prefix).append("?");
prefix= ",";
}
sql.append(" ) values(").append(values).append(")");
ps2 = conn.prepareStatement(sql.toString());
while ( (eachLine = in.readLine()) != null))
{
for (int k=stat; k <=45;k++)
{
ps2.setString (k,main[(k-2)]);
}
stat=45;
for (int l=1;l<= 2; l++)
{
ps2.setString((stat+l),pdp[(l-1)]);// Exception
}
ps2.addBatch();
}
这是错误
java.lang.ArrayIndexOutOfBoundsException:45 在 oracle.jdbc.dbaccess.DBDataSetImpl._getDBItem(DBDataSetImpl.java:378) 在 oracle.jdbc.dbaccess.DBDataSetImpl._createOrGetDBItem(DBDataSetImpl.java:781) 在 oracle.jdbc.dbaccess.DBDataSetImpl.setBytesBindItem(DBDataSetImpl.java:2450) 在 oracle.jdbc.driver.OraclePreparedStatement.setItem(OraclePreparedStatement.java:1155) 在 oracle.jdbc.driver.OraclePreparedStatement.setString(OraclePreparedStatement.java:1572) 在 Processor.main(Processor.java:233)
Hi Guys the following code throws me an error i have an insert statement created once and in the while loop i am dynamically setting parameter , and at the end i says ps2.addBatch() again The code that creates dynamic insert
rs = st.executeQuery("SELECT column_name FROM all_tab_cols
where lower(table_name)= '" + tableName + "' order by column_id");
sql = new StringBuffer(300);
sql.append("insert into ").append( tableName).append("(");
String prefix="";
while (rs.next())
{
sql.append(prefix).append(rs.getString("column_name"));
values.append(prefix).append("?");
prefix= ",";
}
sql.append(" ) values(").append(values).append(")");
ps2 = conn.prepareStatement(sql.toString());
while ( (eachLine = in.readLine()) != null))
{
for (int k=stat; k <=45;k++)
{
ps2.setString (k,main[(k-2)]);
}
stat=45;
for (int l=1;l<= 2; l++)
{
ps2.setString((stat+l),pdp[(l-1)]);// Exception
}
ps2.addBatch();
}
This is the error
java.lang.ArrayIndexOutOfBoundsException: 45
at
oracle.jdbc.dbaccess.DBDataSetImpl._getDBItem(DBDataSetImpl.java:378)
at
oracle.jdbc.dbaccess.DBDataSetImpl._createOrGetDBItem(DBDataSetImpl.java:781)
at
oracle.jdbc.dbaccess.DBDataSetImpl.setBytesBindItem(DBDataSetImpl.java:2450)
at
oracle.jdbc.driver.OraclePreparedStatement.setItem(OraclePreparedStatement.java:1155)
at
oracle.jdbc.driver.OraclePreparedStatement.setString(OraclePreparedStatement.java:1572)
at
Processor.main(Processor.java:233)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
OP需要澄清。这可能有帮助:
OP need to clarify. This might help: