Return ROWID Parameter from insert statement using JDBC connection to oracle

前端 未结 5 748
迷失自我
迷失自我 2020-12-15 13:58

I can\'t seem to get the right magic combination to make this work:


OracleDataSource ods = new oracle.jdbc.pool.OracleDataSource();
ods.setURL(\"jdbc:oracle         


        
5条回答
  •  醉话见心
    2020-12-15 14:33

    A few things you'll need to do

    • Change CallableStatement to OracleCallableStatement
    • Try and return into a NUMBER, ie: OracleTypes.Number

    Sample code for returning info from a query:

    OraclePreparedStatement pstmt = (OraclePreparedStatement)conn.prepareStatement(
           "delete from tab1 where age < ? returning name into ?");
    pstmt.setInt(1,18);
    
    /** register returned parameter
      * in this case the maximum size of name is 100 chars
      */
    pstmt.registerReturnParameter(2, OracleTypes.VARCHAR, 100);
    
    // process the DML returning statement
    count = pstmt.executeUpdate();
    if (count>0)
    {
      ResultSet rset = pstmt.getReturnResultSet(); //rest is not null and not empty
      while(rset.next())
      {
        String name = rset.getString(1);
        ...
      }
    }
    

    More info on Oracle's JDBC extensions:

    • http://download-uk.oracle.com/docs/cd/B19306_01/java.102/b14355/oraint.htm

提交回复
热议问题