Build and execute stored procedure 'on the fly'

Discussion in 'Java' started by iksrazal@terra.com.br, Oct 17, 2005.

  1. Guest

    Hi all,

    I've been requested to build a String that represents a stored
    procedure (SP) dynamically at runtime, and afterwards execute it. The
    DB is beta mysql5. My questions are:

    1) Is it mandatory that in JDBC a SP be called by a CallableStatement?
    For example, a SELECT statement can be built and executed at runtime,
    could this also be done for a SP?
    2) Does a SP need to be installed into the DB before being invoked?

    I ask because I think I my need to install the SP at runtime, after
    being built, and then call it via a CallableStatement. This would
    require, I believe, redirecting the SP to a SQL client shell via Java
    and stdin, and afterwards, invoke the CallableStatement.

    Any ideas?
    iksrazal
    , Oct 17, 2005
    #1
    1. Advertising

  2. Bjorn Abelli Guest

    <> wrote...

    > 1) Is it mandatory that in JDBC a SP be called by a CallableStatement?


    Yes, although "some" JDBC-drivers could provide other means...


    > For example, a SELECT statement can be built and
    > executed at runtime, could this also be done for a SP?


    That depends on the actual JDBC-driver, but I would say that it should work
    in most cases.

    But the creation of an SP is "just" a statement (CREATE PROCEDURE...), so
    you should use a simple "execute(...)" on a simple "Statement" for that.

    > 2) Does a SP need to be installed into the DB before being invoked?


    By its nature an SP is an element in the database, so I can't see how it
    would be possible to call it otherwise... ?

    There's a reason why it's named *stored* procedures... ;-)


    // Bjorn A
    Bjorn Abelli, Oct 17, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. FireListen
    Replies:
    1
    Views:
    481
    James J. Foster
    Jun 27, 2003
  2. Jeff Thur
    Replies:
    2
    Views:
    1,010
    Guest
    Feb 7, 2005
  3. =?Utf-8?B?SklNLkgu?=

    Stored Procedure vs direct execute SQL

    =?Utf-8?B?SklNLkgu?=, May 27, 2005, in forum: ASP .Net
    Replies:
    7
    Views:
    5,018
    Robbe Morris [C# MVP]
    May 27, 2005
  4. nicholas
    Replies:
    7
    Views:
    592
    John.Net
    Aug 3, 2005
  5. Mike P
    Replies:
    0
    Views:
    3,273
    Mike P
    Jun 19, 2006
Loading...

Share This Page