How to create and execute PL/SQL program or Procedure from Java (JDBC)

hi all,
user will enter the Pl/Sql program from User-Interface. that program has to be create in DB and execute that.
due to some confusions, how to execute this from Java, i (user) entered the same logic through a Procedure.
my Java code is
Statement st = con.createStatement();
Statement.execute(procedure_query); // procedure name is myPro
CallableStatement cs = con.prepareCall("{call myPro}");
(as given in SUN docs - http://java.sun.com/docs/books/tutorial/jdbc/basics/sql.html)
but its not creating the procedure.
and i tried to run a procedure (which is already created) with CallableStatement, and this is also not working.
how to get this.
thanks and regards
pavan

Hi,
SInce the PL/SQL block is keyed in dynamically, you probably want to use the anonymous PL/SQL syntax for invoking it:
// begin ? := func (?, ?); end; -- a result is returned to a variable
CallableStatement cstmt3 =
conn.prepareCall(“begin ? := func3(?, ?); end;”);
// begin proc(?, ?); end; -- Does not return a result
CallableStatement cstmt4 =
Conn.prepareCall(“begin proc4(?, ?); end;”);
SQLJ covered in chapter 10, 11, and 12 of my book furnish a more versatile dynamic SQl or PL/SQL mechanisms.
Kuassi
- blog http://db360.blogspot.com/
- book http://db360.blogspot.com/2006/08/oracle-database-programming-using-java_01.html

Similar Messages

  • How to create and execute a function whose return value is  a table

    hi folks ,
    i would like know how to create and execute a function whose return value is a table ,
    am new to pl/sql ,
    my statement for the function is
    SELECT ct.credential_code, c.expiration_date
    FROM certifications c, credential_types ct
    WHERE ct.crdnt_id = c.crdnt_id
    AND c.person_id = person_id;
    i would like to have the result of the above query as return value for the function.
    Thanks in advance ,
    Ashok.c

    hi Ps ,
    Can you please do small sample ,
    that would help me in clear understanding
    thanks in advance
    ashok.c

  • How to create and install a toolbar to a browser using java

    Hi all,
    Can any one guide me about how to create and install toolbar to a browser using java ??
    please any one help me about this,i am not getting any idea about this..
    Thanks and Regards
    Sandesh S

    I doubt you can. Those browser toolbars are done by implementing to an API provided by the browser. That API, I don't believe, is provided via Java. But of course, that would be entirely up to the browser, not Java.

  • How to pass the parameter values to the stored procedure from java code?

    I have a stored procedure written in sqlplus as below:
    create procedure spInsertCategory (propertyid number, category varchar2, create_user varchar2, create_date date) AS BEGIN Insert into property (propertyid, category,create_user,create_date) values (propertyid , category, create_user, create_date); END spInsertCategory;
    I am trying to insert a new row into the database using the stored procedure.
    I have called the above procedure in my java code as below:
    CallableStatement sp = null;
    sp = conn.prepareCall("{call spInsertCategory(?, ?, ?, ?)}");
    How should I pass the values [propertyid, category, create_user, create_date) from java to the stored procedure?[i.e., parameters]
    Kindly guide me as I am new to java..

    Java-Queries wrote:
    I have a stored procedure written in sqlplus as below:FYI. sqlplus is a tool from Oracle that provides a user interface to the database. Although it has its own syntax what you posted is actually PL/SQL.

  • How to call PL-SQL script/stored procedure from Java?

    Assume I want to call a PL-SQL stored procedure from external Java program.
    How can I do this?
    Is there a simple "Hello world" example for this?
    Peter

    This forum is for Oracle only not for java
    Ug

  • How to fetch %ROWTYPE OUT param of  a stored procedure from Java program?

    I have a stored procedure that has IN / OUT parameter as table_name%ROWTYPE.
    From a java program how can I access this ROWTYPE variable?
    I tried all possible documentation and none of the explains whether or not this is supported.
    My use case expect exactly 1 record from the procedure and we would prefer not to use REF CURSOR.
    Is there a way to achieve this? If so, can someone help me with it by posting the sample code to achieve this?
    I tried all the possible OracleTypes to register the OutParameter and they all fail.
    Looks like there isn't any equivalent of %ROWTYPE in OracleTypes either.
    If you need, I can post my sample procedure that uses %ROWTYPE as OUT parameter.
    I really appreciate your help in this regard.
    - Karthik

    Hi,
    If "returning only 1 record" the showstopper for not using Ref Cursor, you might want to reconsider because as you probably know, the ref cursor is only a pointer and requires additional step to retrieve the data.
    Kuassi

  • Passing parameters from java jdbc to pl/sql

    I’m calling stored procedures from java jdbc… but looking for nicer interfaces in terms of passing data. Has anyone come up with a good way to pass data from java jdbc to pl/sql without passing a million parameters? I’m thinking here of some type of structure like pl/sql rowtype or table index type or something else. Has anyone tried to create typed objects in oracle databases and access them from java?
    Thanks, Patrick Caldwell

    Hi Patrick,
    Yes, I have created an Oracle object type, which I successfully returned to a java class, from a PL/SQL stored function, using JDBC. Environment was J2SE 1.3.1, with Oracle 8.1.7.4 on SUN [sparc] Solaris 7 with Oracle's JDBC (thin) driver. It was a while ago, so I don't remember the details very clearly, but I recall being able to figure it out quite easily using the Oracle documentation and the sample code available at Oracle's Technet Web site.
    Hope this has helped you.
    Good Luck,
    Avi.

  • Help on How to compile and execute awt programs

    can any1 say how to compile and execute awt programs
    Edited by: 863765 on Jul 18, 2011 3:29 AM

    EJP wrote:
    The answer is the same for anycode.Oh, but it's not. If he starts with MyClass.java, and we tell him
    javac MyClass.java
    java -cp . MyClassthen that advice won't work when he creates MyClass2. The poor guy will be left lost and alone, with no clue how to proceed! {noformat};-){noformat}

  • How to compile and execute lex,yac,c and java programs

    its the 3rd day on my New MacBook pro..
    as i just migrated from windows to mac i love to work on this..
    The main problem  is i DON't know .......
    how to compile and execute
    1) lex and yac programs
    2) c program
    3) java program
    so please help me
    THIS is the error i got   a1.l is a program
    i got the same error when i used  gcc
    $ lex a1.l
    $ cc lex.yy.c                                 
    Undefined symbols:
      "_yywrap", referenced from:
          _yylex in cc8QDQjW.o
          _input in cc8QDQjW.o
    ld: symbol(s) not found
    collect2: ld returned 1 exit status

    Is the problem that you don't know how to compile and execute these programs on a Mac, or just that you don't know how to compile and execute them?
    Mac OS X is really just a version of BSD Unix, as far as programs like like bison, flex and gcc are concerned...and even when Apple specific versions are provided in the Developer Tools, there are symlinks in the usual places in the Unix file hierarchy.
    For problems with lex and yacc, I suggest you start with their own references, for example, here.
    Or you could just use %option noyywrap, if you only have one file to scan.
    Or you could link to libfl.a using -lfl and use the default version from that library.
    But you really should (as Keith Barkley was subtly hinting at) learn how these tools work and why they work that way.

  • How to compile and execute programing languages

    its the 3rd day on my New MacBook pro..
    as i just migrated from windows to mac i love to work on this..
    but i my main problems is i DON't know .......
    how to compile and execute
    1) lex and yac programs
    2) c program
    3) java program
    so please help me
    THIS is the error i got   a1.l is a program
    i got the same error when i used  gcc
    $ lex a1.l
    $ cc lex.yy.c                                  
    Undefined symbols:
      "_yywrap", referenced from:
          _yylex in cc8QDQjW.o
          _input in cc8QDQjW.o
    ld: symbol(s) not found
    collect2: ld returned 1 exit status

    You're trying to build something that depends on a library you don't have, or haven't referenced. This sort of question belongs in the Developer forums.
    Developer Forums: Apple Support Communities

  • What is varray and how to declare in the pl/sql program

    what is varray and how to declare in the pl/sql program

    1b5595eb-fcfc-48cc-90d2-43ba913ea79f wrote:
    what is varray and how to declare in the pl/sql program
    when all else fails Read The Fine Manual
    Oracle Database Search Results: varray

  • How to compile and execute a Pro*C program on Unix?

    Hello Gurus,
    I am new to Pro*C. I just wrote a sample Pro*C program 'first.pc' to read some information from some tables and print it on screen.
    I am not sure how to compile it and execute it to see the output of my very first program.
    After searching a lot I tried following ..
    -- Step 1 compile the program into .c program
    $->ls -lrt first.pc
    -rwxrwxrwx    1 sqloper4 staff          1069 Oct 31 03:39 first.pc
    $->proc first.pc
    Pro*C/C++: Release 8.1.7.0.0 - Production on Sat Oct 31 05:43:35 2009
    (c) Copyright 2000 Oracle Corporation.  All rights reserved.
    System default option values taken from: /oracle/app/oracle/product/8.1.7/precomp/admin/pcscfg.cfg
    $->ls -lrt first*
    -rwxrwxrwx    1 sqloper4 staff          1069 Oct 31 03:39 first.pc
    -rw-r--r--    1 sqloper4 staff             0 Oct 31 05:43 first.lis
    -rw-r--r--    1 sqloper4 staff          6648 Oct 31 05:43 first.c
    $->
    -- Step 2 Generate the .o file
    $->cc -I${ORACLE_HOME}/precomp/public -c first.c
    first.c: In function 'main':
    first.c:154: warning: return type of 'main' is not 'int'
    $->
    $->ls -lrt first*
    -rwxrwxrwx    1 sqloper4 staff          1069 Oct 31 03:39 first.pc
    -rw-r--r--    1 sqloper4 staff             0 Oct 31 05:43 first.lis
    -rw-r--r--    1 sqloper4 staff          6648 Oct 31 05:43 first.c
    -rw-r--r--    1 sqloper4 staff          3709 Oct 31 05:45 first.o
    $->
    -- Step 3 After that link the .o to libraries and produce the exe
    $->cc -o exe_name -L $ORACLE_HOME/lib -lclntsh
    ld: 0711-317 ERROR: Undefined symbol: .main
    ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more information.
    collect2: ld returned 8 exit status
    $->
    $->ls -lrt first*
    -rwxrwxrwx    1 sqloper4 staff          1069 Oct 31 03:39 first.pc
    -rw-r--r--    1 sqloper4 staff             0 Oct 31 05:43 first.lis
    -rw-r--r--    1 sqloper4 staff          6648 Oct 31 05:43 first.c
    -rw-r--r--    1 sqloper4 staff          3709 Oct 31 05:45 first.o
    $->After all above still I am not sure how to proceed and 'execute' the program.
    Could you please help me with the steps to 'Compile and execute' a Pro*C program ?
    Oracle DB Version : Oracle8i Enterprise Edition Release 8.1.7.4.0 - Production
    OS : Unix
    Thanks in advance!

    Hi All,
    After reading Pro*C Question thread I have tried below steps to compile my .C program, but failed with the given errors
    $->cc -I$ORACLE_HOME/precomp/public -L$ORACLE_HOME/lib first.c -o sample
    ld: 0711-317 ERROR: Undefined symbol: .sqlcxt
    ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more information.
    collect2: ld returned 8 exit statusAfter receiving above error I tried below command as an alternative
    $->cc -I$ORACLE_HOME/precomp/public -L$ORACLE_HOME/lib first.c -o first -lclntsh -lsql10
    collect2: library libsql10 not foundCould you please help in resolving above error? Whats missing exactly?

  • Importing and executing a .sql file into  Oracle 10g

    Hi
    I am looking to import and execute a .sql file(create scripts created of a databse designed in MS SQL Server 2005). The file was imported into Oracle APEX 3.10 but we are unable to execute the script. Please suggest alternatives as to how we can import these files.
    Thanks in advance.

    You likely need to migrate the database (objects and data). This is not so easy and you should have a look to migration tools: http://www.oracle.com/technology/oramag/oracle/07-sep/o57sql.html.

  • How to create an executable

    Hello, I am trying to figure out how to make an executable file from LabVIEW. This is my first time ever creating an executable so I need instructions in basic terms. I tried to do it using the project manager. The file that was created needs LabVIEW Run-Time in order to work.
    Is it even possible to have a LabVIEW program and create an executable that would let any computer without NI products run the appllication?
    Also, I searched for some instructions of how to do this but could not find any useful ones. If anyone can direct me to a post or set of instructions that explain how to create an executable that would be perfect. Thank you!
    Solved!
    Go to Solution.

    Is there any way i can make the RunTime install silently with no user interaction? If I can, how? I have looked at other posts and how NI tell me to do it (http://digital.ni.com/public.nsf/allkb/188FE05BA8933F4486256BC300708527) , but it is way over my head. Is this the right way? or is there a simpler way?
     I do not understand how to compile the installer and executable file together. I can create the executable from the LabVIEW file that I need to run, but I want the RunTime to install automatically before that executable is executed. (If this statement doesnt make sense, tell me. )
    Any feedback would be appreciated.

  • How to create CATALOG with MS SQL Server?

    Connection class has getCatalog(strCatalog) method. In order to use it, we must create CATALOG in Database?
    How to create CATALOG with MS SQL Server?
    Help me, please!!!

    You do not create these for any database, this is part of the Connection metadata.
    The Catalog is the third level of table-like database object qualification as in "Catalog.Schema.Table". For SQLServer the qualification scheme is "Database.Owner.Table" and I would be surprised if they reported anything for the current connections getCatalog() method call.
    What many people do is avoid table qualification altogether by setting the connection's context in a database proprietary manner and then keeping the SQL as clean as possible. For many ODBC and JDBC drivers this can be set in the configuration. For MS SQLServer you can also execute a "USE dbname" statement on the connection to avoid table qualification.

Maybe you are looking for

  • No longer able to adjust the length of a video clip in imovie 6 HD

    Without warning (or reason) I can no longer adjust the length of a video clip (new or old) in imovie. I've tried the old way of highlighting the clip and putting the cursor at the start or end, but the cursor doesn't change. I've also tried double cl

  • App error VC003 - iPhone only

    Hello, I have been using the BT sport app successfully for months, on my iPhone (occasionally I use the website with my laptop). Recently I bought a tablet (Samsung), so I started using the app on the tablet, all good as well! But in the last couple

  • Bluettooth stays in searching mode.

    I have a black/slate iphone 5 and the bluetooth does not work. it stays in discovery and refuses to stop searching. I have paired my headsets previously and now it just refuses to stop searching. I can't even see if the headsets are still paired as t

  • Interactive slideshows

    Hi, I'm looking to make an interactive slideshow for my website. As a photographer, I would like to be able to have each categorical page of photos be easy to scroll through without clicking a large number of thumbnails. An example of what I would li

  • How Do I Get the Best Range with the Express?

    What settings should I use to get the best range with the express? What Radio Mode, Multicast Rate and Transmit Power should I use? What is the estimated area that this will cover?