java 批量执行存储过程_Java:如何从其他模式执行存储过程

执行过程 isb.pkg_po_test.get_component ,我必须从远程数据库获取一个游标 .

我们的架构是 ISBREPORTER ,我们对架构 ibs 的访问权限有限 . 但是,在Oracle SQL Plus上,以下执行得非常好:

SQL> var r refcursor SQL> exec isb.pkg_po_test.get_component(15048,6,1,1,to_date('17 .12.2017'),:r); SQL> print;

印刷结果:

ID PRODUCT_TYPE_ID COMPONENT_ID COMPONENT_NAME

1 1 1012161 some text_1

2 1 1012160 some text_2

3 1 1012158 some text_3

4 1 10078 some text_4

5 1 10078 some text_5

6 1 10040 some text_6

7 1 1012149 some text_7

当我尝试从java代码调用它时,我得到以下异常:

java.sql.SQLException: ORA-06550: line 1, column 7:

PLS-00201: identifier 'ISB.PKG_PO_TEST must be declared

ORA-06550: line 1, column 7:

PL/SQL: Statement ignored

at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:450)

at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:399)

at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:1017)

at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:655)

at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:249)

at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:566)

at oracle.jdbc.driver.T4CCallableStatement.doOall8(T4CCallableStatement.java:210)

at oracle.jdbc.driver.T4CCallableStatement.doOall8(T4CCallableStatement.java:53)

at oracle.jdbc.driver.T4CCallableStatement.executeForRows(T4CCallableStatement.java:938)

at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1075)

at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3820)

at oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStatement.java:3923)

at oracle.jdbc.driver.OracleCallableStatement.execute(OracleCallableStatement.java:5617)

at oracle.jdbc.driver.OraclePreparedStatementWrapper.execute(OraclePreparedStatementWrapper.java:1385)

at org.apache.tomcat.dbcp.dbcp2.DelegatingPreparedStatement.execute(DelegatingPreparedStatement.java:197)

at org.apache.tomcat.dbcp.dbcp2.DelegatingPreparedStatement.execute(DelegatingPreparedStatement.java:197)

这是我从java调用它的方式:

public void printCursor(PrintWriter out) {

Connection ktConnection;

try {

ktConnection = ConnectionPool.getConnectionKT();

} catch (SQLException e) {

e.printStackTrace();

return;

}

String statement = "{CALL isb.pkg_po_test.get_component(?,?,?,?,?,?)}";

try {

CallableStatement call = ktConnection.prepareCall(statement);

call.setFloat(1, 15048);

call.setFloat(2, 6);

call.setFloat(3, 1);

call.setInt(4, 1);

call.setDate(5, Date.valueOf("2017-12-17"));

call.registerOutParameter(6, OracleTypes.CURSOR);

call.execute();

ResultSet rs = (ResultSet) call.getObject(6);

while (rs.next()) {

String column = rs.getString("COMPONENT_NAME");

out.print(column); //to test if it is working

}

} catch (SQLException e) {

e.printStackTrace();

}

}

从其他模式执行存储过程是否正确?如果没有,你能告诉我如何正确处理它吗?

我已经阅读了其他类似的问题,这些问题没有帮助 . 这里是其中的一些:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
想要Java向MySQL批量存储数据,可以通过以下步骤实现: 1. 创建MySQL数据库和表,确保表中的字段与Java中数据对象的属性一一对应。 2. 在Java中,使用JDBC连接MySQL数据库。 3. 使用PreparedStatement对象预编译SQL语句,例如: ``` String sql = "INSERT INTO table_name (column1, column2, column3) VALUES (?, ?, ?)"; PreparedStatement statement = connection.prepareStatement(sql); ``` 4. 创建一个List,将需要插入的数据对象添加到List中。 5. 循环遍历List,对于每个数据对象,使用PreparedStatement设置参数,最后将PreparedStatement添加到批处理中,例如: ``` for (DataObject data : dataList) { statement.setString(1, data.getProperty1()); statement.setInt(2, data.getProperty2()); statement.setDouble(3, data.getProperty3()); statement.addBatch(); } ``` 6. 执行批处理,将数据批量插入到MySQL中,例如: ``` int[] result = statement.executeBatch(); ``` 完整的Java代码示例: ``` String sql = "INSERT INTO table_name (column1, column2, column3) VALUES (?, ?, ?)"; PreparedStatement statement = connection.prepareStatement(sql); List<DataObject> dataList = getDataList(); for (DataObject data : dataList) { statement.setString(1, data.getProperty1()); statement.setInt(2, data.getProperty2()); statement.setDouble(3, data.getProperty3()); statement.addBatch(); } int[] result = statement.executeBatch(); ``` 注意事项: - 执行批处理前,需要关闭自动提交模式,即使用`connection.setAutoCommit(false)`。 - 执行完批处理后,需要手动提交事务,即使用`connection.commit()`。 - 执行批处理前,建议先关闭索引,执行完成后再重新开启索引,可以提高插入效率。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值