inline SQL PL over JDBC

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kenevel

    #1

    inline SQL PL over JDBC

    Hi there,

    Is it possible to use inline SQL PL over JDBC? If so, which statement
    type is required and what syntax does the inline SQL PL take? A
    CallableStateme nt, for example, need to be enclosed within curly
    braces: eg:

    {CALL some_procedure( )}

    Cheers

    Michael

  • Serge Rielau

    #2
    Re: inline SQL PL over JDBC

    Kenevel wrote:
    Hi there,
    >
    Is it possible to use inline SQL PL over JDBC? If so, which statement
    type is required and what syntax does the inline SQL PL take? A
    CallableStateme nt, for example, need to be enclosed within curly
    braces: eg:
    Not clear I understand your question...
    Ar eyou asking whether you can submit a BEGIN ATOMIC ... END from JDBC?
    The answer to that AFAIk is yes. Use the same API you use for e.g. UPDATE.

    Cheers
    Serge
    --
    Serge Rielau
    DB2 Solutions Development
    IBM Toronto Lab

    Comment

    • Knut Stolze

      #3
      Re: inline SQL PL over JDBC

      Kenevel wrote:
      Hi there,
      >
      Is it possible to use inline SQL PL over JDBC? If so, which statement
      type is required and what syntax does the inline SQL PL take? A
      CallableStateme nt, for example, need to be enclosed within curly
      braces: eg:
      >
      {CALL some_procedure( )}
      That is not correct. You can call a stored procedure through JDBC simply
      this way:

      CALL some_procedure( ...)

      Have a look at the samples, specifically
      sqllib/samples/java/jdbc/SpClient.java.

      --
      Knut Stolze
      DB2 z/OS Utilities Development
      IBM Germany

      Comment

      • Kenevel

        #4
        Re: inline SQL PL over JDBC

        On 21 Feb, 12:49, Serge Rielau <srie...@ca.ibm .comwrote:
        >
        Not clear I understand your question...
        Are you asking whether you can submit a BEGIN ATOMIC ... END from JDBC?
        The answer to that AFAIk is yes. Use the same API you use for e.g. UPDATE.
        >
        Hi Serge,

        Yes: I am asking whether I can submit a BEGIN ATOMIC ... END over
        JDBC. There are advantages from an application-packaging point-of-view
        if you can keep this sort of logic within the Java application itself,
        rather than installing the same logic in the DB as a stored procedure
        or function - both from a deployment and a rollback perspective.

        My problem is that the simple examples I've tried have invariably all
        complained about the syntax - so I wondered whether anyone knew the
        exact Java statement type (eg: Statement, CallableStateme nt,
        PreparedStateme nt) to use, and also the associated syntax (hence the
        quick example in my first post of how the syntax for a
        CallableStateme nt varies from a Statement or PreparedStateme nt).

        Cheers

        Michael

        Comment

        • Serge Rielau

          #5
          Re: inline SQL PL over JDBC

          I may be dumb, but I know people ... ;-)
          Try this:

          Statement stmt = con.createState ment();
          stmt.execute( "begin atomic" +
          " insert into t1 values (1);" +
          " insert into t1 values (2);" +
          "end" );

          PreparedStateme nt pstmt = con.prepareStat ement(
          "begin atomic" +
          " insert into t1 values (?);" +
          " insert into t1 values (?);" +
          "end" );

          pstmt.setInt( 1, 3 );
          pstmt.setInt( 2, 4 );
          pstmt.execute() ;

          Cheers
          Serge

          --
          Serge Rielau
          DB2 Solutions Development
          IBM Toronto Lab

          Comment

          • Knut Stolze

            #6
            Re: inline SQL PL over JDBC

            Kenevel wrote:
            My problem is that the simple examples I've tried have invariably all
            complained about the syntax - so I wondered whether anyone knew the
            exact Java statement type (eg: Statement, CallableStateme nt,
            PreparedStateme nt) to use, and also the associated syntax (hence the
            quick example in my first post of how the syntax for a
            CallableStateme nt varies from a Statement or PreparedStateme nt).
            What exactly are those statements and what are the errors you got from DB2?
            As Serge said, compound statements are regular SQL statements and you can
            execute them as usual through JDBC. So I would suspect a problem with your
            application.

            --
            Knut Stolze
            DB2 z/OS Utilities Development
            IBM Germany

            Comment

            Working...