Results 1 to 5 of 5

Thread: Can JDBC outbound-channel-adapter invoke a database function?

  1. #1
    Join Date
    May 2011
    Location
    Athens, Greece
    Posts
    3

    Default Can JDBC outbound-channel-adapter invoke a database function?

    Hi all,

    Is it possible for a JDBC outbound-channel-adapter to invoke a database function, instead of performing an insert or update query?

    If not, are there any alternatives in order to achieve this?

    Thanks for your help.

  2. #2
    Join Date
    Jan 2008
    Location
    Mohnton, PA USA (that's near Philadelphia)
    Posts
    2,148

    Default

    You can have a service-activator with custom class which would invoke the DB function.
    Does that explain?

  3. #3
    Join Date
    May 2011
    Location
    Athens, Greece
    Posts
    3

    Default

    Hi Oleg, thanks for the reply.

    This gives me a hint more or less. I will try to elaborate on your proposed solution and probably come up with new questions/details.

  4. #4
    Join Date
    May 2011
    Location
    Athens, Greece
    Posts
    3

    Default

    Hi again Oleg,

    Is that what you meant by defining a method in custom class?

    Code:
    @ServiceActivator
        public void invokeDBFunction() throws SQLException {
            Connection con = null;
            CallableStatement cstmt = null;
            try {
                con = ds.getConnection();
                try {
                    cstmt = ds.getConnection().prepareCall("select fire(?, ?)");
                    cstmt.setInt(1, 100);
                    cstmt.setString(2, "One Hundred");
                    cstmt.executeUpdate();
                } catch (SQLException sqle) {
                    if (cstmt != null) {
                        cstmt.close();
                    }
                }
            } catch (SQLException sqle) {
                if (con != null) {
                    con.close();
                }
            }
        }
    
     <service-activator input-channel="channelIn"
                           output-channel="channelOut"
                           ref="service"
                           method="invokeDBFunction"/>

  5. #5
    Join Date
    Mar 2010
    Location
    Gtr Philadelphia, PA
    Posts
    2,022

    Default

    Do you not need any data from the message in channelIn?

    By returning void, no response will be sent to channelOut.

    Also, you might want to consider subclassing Spring's StoredProcedure class; that way you can avoid all that nasty JDBC connection handling code - let Spring do it for you.
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •