Ask Your Question
0

How can I pass an Oracle Object that has a Blob to SimpleJdbcCall?

asked 2021-08-28 11:00:00 +0000

devzero gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2021-04-29 13:00:00 +0000

bukephalos gravatar image

You can pass an Oracle Object that has a Blob to SimpleJdbcCall by following these steps:

  1. Define a custom class that mirrors the Oracle Object you are trying to pass. For example, if your Oracle Object is named "MYOBJECT" and has a property "MYBLOB", you can define a class like this:
public class MyObject {
   private Blob myBlob;

   public Blob getMyBlob() {
      return myBlob;
   }

   public void setMyBlob(Blob myBlob) {
      this.myBlob = myBlob;
   }
}
  1. Create an instance of this class and set the Blob property appropriately:
MyObject obj = new MyObject();
obj.setMyBlob(myBlob);
  1. Create an instance of SimpleJdbcCall and set the appropriate parameters:
SimpleJdbcCall jdbcCall = new SimpleJdbcCall(jdbcTemplate)
   .withProcedureName("MY_PROCEDURE")
   .declareParameters(
      new SqlParameter("MY_OBJECT", OracleTypes.STRUCT, "MY_OBJECT_TYPE", new SqlUserDefinedTypeValue<MyObject>("MY_OBJECT_TYPE", obj))
   );

In this example, "MYPROCEDURE" is the name of the stored procedure you want to call, "MYOBJECTTYPE" is the name of the Oracle Object type, and "MYOBJECT" is the parameter name. The last parameter sets the value of the parameter to an instance of the MyObject class you created earlier.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-08-28 11:00:00 +0000

Seen: 23 times

Last updated: Apr 29 '21