Create java procedure using jdbc

Hi,
I am trying to create java procedure using jdbc connection, I am using Oracle 11.2. When I create the procedure using sqlplus it works fine. Using jdbcit fails; code sniplet below:
               ddl =
               "create or replace java source named \"UTLCMD\" as \r\n"+
               "import java.lang.Runtime; \r\n"+
               "public class execHostCommand \r\n"+
               "{ \r\n"+
               "public static void execute (String command) \r\n"+
               " throws java.io.IOException \r\n"+
               " { \r\n"+
               " Runtime rt = java.lang.Runtime.getRuntime(); \r\n"+
               " rt.exec(command); \r\n"+
               " } \r\n"+
               statement = conn.createStatement();
               statement.executeUpdate(ddl);
I am getting this error:
2013-01-26 12:45:31.835 UTC: ERROR: Exception "java.sql.SQLException: ORA-29536: badly formed source: Encountered "ublic" at line 3, column 1.
Was expecting one of:
"extends" ...
"implements" ...
"<" ...
". Stack dump:

Hi,
We can load java class using blob column, for example :
create or replace and compile java class using blob select code from java_code;If class is OK, but resolution of referenced names to other classes failed, statement.execute() will not show any error and we need to 'select from user_errors' view for errors. How can we got the required object name for loaded class?

Similar Messages

  • Creating and calling stored procedure using jdbc

    When I try to create and call a stored procedure using JDBC a very confusing error message about non-existence of the procedure just created is thrown. Using Informix database (IDS 10). Any pointers to point out what am doing wrong would be great!
    Thanks
    import java.io.FileNotFoundException;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.SQLException;
    import java.sql.Statement;
    import java.util.Scanner;
    public class CreateStoredProc {
    public static void main(String args[]){
    if (0 == args.length)
    return;
    try {
    Class.forName("com.informix.jdbc.IfxDriver");
    Connection conn = DriverManager.getConnection("jdbc:informix-sqli://10.76.244.120:30000/sampledb:INFORMIXSERVER=krisunda;user=root;password=cisco");
    String q = " create procedure runproc() "+
    " define i int; "+
    " let i = 0; "+
    " end procedure; "+
    " execute procedure runproc(); ";
    Statement stmt = conn.createStatement ();
    stmt.execute (q);
    } catch (Exception e) {
    e.printStackTrace();
    The stack trace:
    java.sql.SQLException: Routine (runproc) can not be resolved.
    at com.informix.jdbc.IfxSqli.a(IfxSqli.java:3204)
    at com.informix.jdbc.IfxSqli.E(IfxSqli.java:3518)
    at com.informix.jdbc.IfxSqli.dispatchMsg(IfxSqli.java:2353)
    at com.informix.jdbc.IfxSqli.receiveMessage(IfxSqli.java:2269)
    at com.informix.jdbc.IfxSqli.executeExecute(IfxSqli.java:2157)
    at com.informix.jdbc.IfxSqli.executeExecute(IfxSqli.java:2132)
    at com.informix.jdbc.IfxResultSet.b(IfxResultSet.java:378)
    at com.informix.jdbc.IfxStatement.a(IfxStatement.java:1299)
    at com.informix.jdbc.IfxStatement.executeImpl(IfxStatement.java:1269)
    at com.informix.jdbc.IfxStatement.c(IfxStatement.java:989)
    at com.informix.jdbc.IfxStatement.execute(IfxStatement.java:875)
    at CreateStoredProc.main(CreateStoredProc.java:37)
    Caused by: java.sql.SQLException
    at com.informix.util.IfxErrMsg.getSQLException(IfxErrMsg.java:373)
    at com.informix.jdbc.IfxSqli.E(IfxSqli.java:3523)
    ... 10 more

    DriverManager.getConnection("jdbc:informix-sqli://10.76.244.120:30000/sampledb:INFORMIXSERVER=krisunda;user=root;password=cisco");check with ur sys admin wheather the particular user in the database has >execute privilage(rights) also.i mean execute the SP in the DB level.I guess that a root user will have the enough right.
    String q = " create procedure runproc() "+
    " define i int; "+<" let i = 0; "+
    " end procedure; "+
    " execute procedure runproc(); ";
    Statement stmt = conn.createStatement ();
    stmt.execute (q);Try to use the following code:
    String q = " create procedure runproc() "+
    " define i int; "+
    " let i = 0; "+
    " end procedure; "
    Statement stmt = conn.createStatement ();
    stmt.execute (q);
    q=" execute procedure runproc(); ";
    stmt.execute (q);
    Because maybe the driver failed to precompile your sql once, so that nothing happen.

  • Weird Problem calling Stored Procedure using JDBC

    Scenario is..
    I have J2EE application and calling stored procedure using JDBC.
    My application connects to instance "A" of testDB.
    Schema "A" does NOT own any packages/procedure but granted execute on oracle packages/procedures that reside in schema "B" of testDB.
    In java code I call procedure(proc1) in package(pac1) which internally calls procedure(proc2) in package(pac2).
    The problem occurs when procedure pac2.proc2 is modified. After the modification, my java code fails and throws an exception "User-Defined Exception" and I am also getting "ORA-06508: PL/SQL: could not find program unit being called". This clears up only if I bounce the web container. (This doesn't happen if I modify pac1.proc1 and run my application)
    Has any one faced this problem? Please suggest if any thing can be changed in jdbc code to fix this problem.
    Thanks

    Hi,
    I assume these are PL/SQL packages and that the changes are made at the package specification level?
    If so, it looks like you are hitting the PL/SQL dependencies rules. In other words, if the spec of proc2 is changed, then proc1 is invalidated, since proc1 still depends on the old version of proc2's spec. As a result, if you try to run proc1, its spec must either be explicitly rewritten before it could run again or implicitly recompiled first, if the (implicit) recompilation fails, it won’t run.
    Kuassi http://db360.blogspot.com

  • Calling a procedure using JDBC-OCI

    When I use setPlsqlIndexTable for calling a procedure using JDBC-OCI
    ps.setPlsqlIndexTable(1,str,10,str.length,OracleTypes.VARCHAR,8);
    always throw a Exception :
    java.sql.SQLException: Non supported character set: oracle-character-set-832
    at oracle.gss.util.NLSError.throwSQLException(NLSError.java:46)
    at oracle.sql.CharacterSetUnknown.failCharsetUnknown(CharacterSetFactoryThin.java:171)
    at oracle.sql.CharacterSetUnknown.convert(CharacterSetFactoryThin.java:135)
    at oracle.sql.CHAR.<init>(CHAR.java:133)
    at oracle.sql.CHAR.<init>(CHAR.java:157)
    at oracle.jdbc.oracore.OracleTypeCHAR.toDatum(OracleTypeCHAR.java:145)
    at oracle.jdbc.oracore.OracleType.toDatumArray(OracleType.java:145)
    at oracle.jdbc.oracore.OracleTypeCHAR.toDatumArray(OracleTypeCHAR.java:173)
    at oracle.jdbc.driver.OraclePreparedStatement.setPlsqlIndexTable(OraclePreparedStatement.java:2622)
    When can tell me how to solve it? Thanks

    I hava resolve this problem, we must add the
    class nls_charset12.zip to classpath.

  • How to create java archive using jar command

    hello
    what is the syntax for creating java acrchive using jar command line
    jar -c ???????
    urgent plzz

    jar cf myjar.jar classfiles...
    If you have a manifest file you want to add:
    jar cfm myjar.jar manifest.mf classfiles...
    Also check the documentation:
    http://java.sun.com/j2se/1.3/docs/tooldocs/tools.html
    You can find a link to jar there.

  • How to get return type as Table of Index by BINAR from Procedure using JDBC

    Hi,
    We have stored procedure which takes Varchar as input and rerurn muiltiple recored of type Table of index by BINARY
    We created the procedure with in a package, its header part like below:
    CREATE OR REPLACE PACKAGE emp_pkid_pkg
    AS
    TYPE r_emp IS RECORD ( employe_profile_id NUMBER
    , client_profile_id VARCHAR2(240)
    , email VARCHAR2(240)
    , terms_acp VARCHAR2(1)
    TYPE tp_emp_profile IS TABLE OF r_emp INDEX BY BINARY_INTEGER;
    PROCEDURE er_employe_prov_profile ( e_inxid employe_provision_instance.inxid%TYPE
    , e_emp_recs OUT tp_emp_profile
    END emp_pkid_pkg;
    This procedure has body part, wich has origial business logic like below.
    CREATE OR REPLACE PACKAGE BODY emp_pkid_pkg
    AS
    PROCEDURE pr_customer_prov_profile ( e_inxid employe_provision_instance.inxid%TYPE
    , e_emp_recs OUT tp_customer_provision_profile
    IS
    CURSOR c_emp_prov_instance ( c_guid employe_provision_instance.guid%TYPE )
    etc ...
    END emp_pkid_pkg;
    We could execute the below script from oracle client tool and get the response.
    DECLARE
    e_cust emp_pkid_pkg.tp_emp_profile;
    BEGIN
    emp_pkid_pkg.er_employe_prov_profile ( 'ef45t6543y98'
    , e_cust
    FOR i in e_cust.FIRST..e_cust.LAST LOOP
    DBMS_OUTPUT.PUT_LINE ( e_cust(i).employe_profile_id
    ||'#'|| e_cust(i).client_customer_id
    ||'#'|| e_cust(i).email
    ||'#'|| e_cust(i).term_acp);
    END LOOP;
    END;
    We have requirement to get the results from procedure usind JDBC callable statement call.
    We have tried to call the procedure via JDBC callable statement but it didn't work.
    We have constructed it like the following. It was throwing error "java.sql.SQLException: invalid column type: emp_pkid_pkg.tp_emp_profile
    CallableStatement cs2 = con.prepareCall("{call emp_pkid_pkg.er_employe_prov_profile(?,?)}");
    cs2.registerOutParameter(2, OracleTypes.CURSOR, emp_pkid_pkg.tp_emp_profile);
    cs2.setString(1,empId);
    Not sure whether I am doing the logic correctly. But i tryed with diff type. Still am getting same error like above.
    Please point me to the correct approach.
    Thanks
    Edited by: 921689 on 18-Mar-2012 17:20

    >
    We have requirement to get the results from procedure usind JDBC callable statement call.
    >
    Can't be done - the reason has nothing to do with JDBC so you are in the wrong forum.
    Repost in the PL/SQL forum and I can give you an example of what you have to do
    PL/SQL
    First the TYPEs you defined are PL/SQL types so can't be referenced outside PL/SQL; you need to define SQL types.
    Second you will need to use a procedure that returns a REF CURSOR or is a PIPELINED procedure. Since your procedure doesn't fall into either category you can't use it with JDBC to do what you want.
    If your query was a PIPELINED function then you could simply query it like it was a table. I have a PIPELINED function name 'get_emp' so this works.
    select * from table(get_emp(30));Post in the PL/SQL forum and I can give you the code for the procedure. I'm not going to clutter up this forum with inappropriate material.

  • Compile Stored Procedure using JDBC ?

    I am using JDBC thin driver and able to create stored procedure without any problem.
    But if the stored procedure is invalid, it
    won't throw SQLException during creation.
    Is there any way that I can compile the
    stored procedure and catch the semantic exception during creation ?
    Please help, thanks.
    null

    The only thing that springs to mind is the user_errors view. If the procedure fails to compile, then there will be rows in this view indicating the error ..... so maybe you could use
    select count(*) from user_errors
    and check from Java that 0 is returned.

  • Passing XMLType Data into oracle stored procedure using JDBC

    Hi Friends,
    I have requirement where my oracle stored procedure accepts XML file as an input. This XML File is generated in runtime using java, I need to pass that xml file using JDBC to oracle stored procedure. Please let me know the fesibile solution for this problem.
    Following are the environment details
    JDK Version: 1.6
    Oracle: 10g
    Server: Tomcat 6.x
    Thanks in Advance

    user4898687 wrote:
    I have requirement where my oracle stored procedure accepts XML file as an input. This XML File is generated in runtime using java, I need to pass that xml file using JDBC to oracle stored procedure. Please let me know the fesibile solution for this problem.As stated - no.
    A 'file' is a file system entity. There is no way to pass a 'file' anywhere. Not PL/SQL. Not java.
    Now you can pass a file path (a string) in java and to PL/SQL.
    Or you can pass xml data (a string) in java and to PL/SQL. For PL/SQL you could use eithe a varchar2, if the xml is rather small, or a blob/clob.

  • Can't execute Oracle Stored Procedure using JDBC

    Hi all,
    I'm fairly new to JDBC and Oracle, so pardon my ignorance/lack of knowledge in this subject matter. I am trying to call a stored procedure named get_countries that has no parameters using JDBC. I do this by executing the following lines of code:
    CallableStatement cs = con.prepareCall("{call get_countries}");
    ResultSet rs = cs.executeQuery();But I get the following exception thrown:
    Exception in thread "main" java.sql.SQLException: ORA-06550: line 1, column 7:
    PLS-00306: wrong number or types of arguments in call to 'GET_COUNTRIES'
    ORA-06550: line 1, column 7:
    PL/SQL: Statement ignored
    at oracle.jdbc.driver.DatabaseError.throwSqlException(_DatabaseError.java:112_)
    at oracle.jdbc.driver.T4CTTIoer.processError(_T4CTTIoer.java:331_)
    at oracle.jdbc.driver.T4CTTIoer.processError(_T4CTTIoer.java:288_)
    at oracle.jdbc.driver.T4C8Oall.receive(_T4C8Oall.java:745_)
    at oracle.jdbc.driver.T4CCallableStatement.doOall8(_T4CCallableStatement.java:218_)
    at oracle.jdbc.driver.T4CCallableStatement.executeForRows(_T4CCallableStatement.java:969_)
    at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(_OracleStatement.java:1190_)
    at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(_OraclePreparedStatement.java:3370_)
    at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(_OraclePreparedStatement.java:3415_)
    at JDBCTest.main(_JDBCTest.java:44_)
    This makes no sense to me because there are no parameters that I need to pass. So I'm guessing this is something that I don't know about JDBC or about Oracle. I've searched Google for the past hour and a half and still haven't found anything that explains what might be the problem. I've also been following this guide ([http://java.sun.com/docs/books/tutorial/jdbc/basics/sql.html]) and I'm doing it exactly the same way, but for some reason it works for them.
    Anyone know what I'm doing wrong?
    Thanks for your help in advance. I really appreciate it!

    I went to a few forums and asked the same question. The boys down at Oracle Community Forums shed some light on this subject and, with their help, I was able to figure it out. Here is the thread for those who want to read: [My Thread @ Oracle Community Forums|http://forums.oracle.com/forums/thread.jspa?messageID=2721348?].
    THE SOLUTION
    cs = con.prepareCall("{ call get_countries(?) }");
    cs.registerOutParameter(1, OracleTypes.CURSOR);
    cs.execute();
    ResultSet rs = ((OracleCallableStatement) cs).getCursor(1);

  • Urg:Executing SQL From Java App using Jdbc Driver

    Hi
    I am using JDBC Driver version 9.0.1.1.0.
    I am running this in Thin Client Mode
    My Code Snippet Looks Like This:=
    ==========================================================
    String url = "jdbc:oracle:thin:@localhost:1521:VpDb";
    String userName = "scott";
    String password = "tiger";
    Connection conn = null ;
    Statement st = null ;
    ResultSet rs = null ;
    String categoryCode="ABC";
    try
    conn = DriverManager.getConnection (url, userName, password);
    st = conn.createStatement ();
    String sqlStatement = "Select Count(*) From News Where CategoryCode=" +"\'" + categoryCode + "\'" + ";";
    System.out.println(sqlStatement);
    rs = st.executeQuery ( sqlStatement );
    if( rs.next() )
    System.out.println("Headline Exists");
    else
    System.out.println("No Headline Exists");
    catch (SQLException e )
    System.out.println();
    System.out.println (" SQL ERROR IN IS_NEWS_EMPTY: " + e) ;
    =========================================================
    I have added the classes12.zip and nls_charset12.zip in the classpath.
    Now when i run this it gives me an error saying the following error message:-
    SQL ERROR IN IS_NEWS_EMPTY: java.sql.SQLException: ORA-00911: invalid character
    Can anyone help me with this as to whats going wrong because the exact equivalent of my sqlStamenet runs on SQL command line but not from java code.Why??
    Any Help appreciated
    Thanks
    Mum

    I think it is complaining about the ";" that you add at the end of your string. You don't need to add that to the query.

  • Urgent !!!!!!!!!!!! regarding CREATE JAVA CLASS USING BFILE

    We have Oracle 8.1.7 spatial database. We got to load some java classes into the database. We would like to make it as the java programs to be loaded from a client system into the oracle server. I am using CREATE DIRECTORY command to create a directory object (say suppose \\prav\loadjavaclasses\. Then using the CREATE OR REPLACE JAVA CLASS USING BFILE (object_name, 'CLASSNAME.CLASS'). This .class file is in the network identified by prav which in turn has a shared directory (full privileges) loadjavaclasses folder. Can you please help in this regard.
    Please mail me to [email protected]
    thanks in advance
    SudhaSrikanthan
    null

    use loadjava

  • How to create a procedure using program unit

    Hai All
    Ii have created a procedure like this
    PROCEDURE Duty_calc
    IS
    procedure w_Time
    is
    begin
    update dail_att set wtime= (select lpad((to_number(to_char(outtime,'hh24mi')-to_char(intime,'hh24mi'))),4,0) from dail_att where attend_date=f_date);
    end w_time;
    begin
    if wtime >0830 then
    update dail_att set etime= (select lpad(wtime-0830) from dail_att where attend_date=f_date);
    else
         null;
    end if;
    duty_calc;
    end duty_calc;
    And i have declare in the program unit as Duty_calc and while i am executing my procedure i had an error
    is it must i need to declare a my inner procedure in my program unit
    Regards
    Srikkanth.M

    the same question you asked 2 month ago and same mistake you are doing
    - Procedure name can only be one.
    - Count proper BEGIN ENDs
    PROCEDURE Duty_calc
    IS
    BEGIN
    begin
    update dail_att set wtime= (select lpad((to_number(to_char(outtime,'hh24mi')-to_char(intime,'hh24mi'))),4,0) from dail_att where attend_date=f_date);
    end;
    begin
      if wtime >0830 then
      update dail_att set etime= (select lpad(wtime-0830) from dail_att where attend_date=f_date);
    else
      null;
    end if;
    end;
    END;

  • Calling stored procedure using jdbc

    Hi all,
    I'm new to jdbc calling pl/sql and I have a very simple question. I'd like to execute this before I read data from the table:
    BEGIN
    packageA.functionA(1234567890123456);
    END;
    My jdbc code:
    try {
    DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());
    conn = DriverManager.getConnection("jdbc:oracle:thin:@host", "username", "passwd");
    Statement stmt = conn.createStatement();
    CallableStatement cs = conn.prepareCall ("begin packageA.procedureA (?); end;");
    cs.setBigDecimal(1,new BigDecimal(1234567890123456.0D));
    cs.execute();
    } catch {...}
    I get the following error:
    java.sql.SQLException: ORA-01403: no data found
    ORA-06512: at "db.packageA", line 2639
    ORA-06512: at line 1
    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
         at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:289)
         at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:573)
         at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1891)
         at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteFetch(TTC7Protocol.java:1093)
         at oracle.jdbc.driver.OracleStatement.executeNonQuery(OracleStatement.java:2047)
         at oracle.jdbc.driver.OracleStatement.doExecuteOther(OracleStatement.java:1940)
         at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2709)
         at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:589)
         at oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStatement.java:656)
    Please advise...
    Thanks!
    M

    Hi M,
    as you can see from the error message, you are indeed calling packageA. The error happens on line 2639 of this package, so this is not a JDBC problem.
    Regards,
    Pit

  • Forms 11g Win7 - Unable to create JAVA procedure

    Hi,
    When I click "Program Unit" -> "New", I see there is a possibilty to create a Java Source, but it is deactivated.
    Java is not installed in the Database, maybe that's the reason.
    Many thanks for your help.

    >
    Where s default.env located by default?
    When I searched for this file inside WebLogic (configured with Forms) , default.env could be located only in
    D:\Installs\WebLogic10.3.2\user_projects\domains\ClassicDomain\servers\WLS_FORMS\tmp\_WL_user\formsapp_11.1.1\wb1h9e\configThis is not the location of default.env. If you want u can update that using EM
    http://machine:port/em
    If you search for default.env in user_projects directory you might probably get two listed. Take the other an than the one you listed here. It will not be in tmp directory.

  • Multiple stored procedures using JDBC Adopter, Synchronous call

    Hello Guys,
    This is kind of different scenario,
    Here is the scenario (SQL Server -> XI -> Legacy)
    1.I want to trigger stored procedure (from XI to)
    2.Inside the stored procedure we are going to have multiple stored procedures.
    -Inside stored procedures
    SP1 -> It supposed to select the data from interface control table, if that is success
    SP2 -> Call some other stored procedures which can be select/insert/delete from different tables most of the cases it would be select, if that is success
         It should give results back (Response) to XI and with some output parameters like (status message, etc…)
    Next step I want send those results to target system which is legacy. If that is success
    Next step I should update entry in the Interface control table(which is in SQL Server) with success entry like (success message, current date, current time, interface name, username.) 
         If it fails any stage like while selecting data from interface control table which is SP1/ SP2 It should give error message back to XI(output parameters). XI is going to send Alerts/Mails to respective interface owners.
    This is my scenario can anybody help me on this what needs to be done to implement this scenario.

    Hi Murali,
    Anyway , altimately you are going to call one stored procedure and going to get one output. So it will not be a problem I think.
    Anyway it is required to introduce BPM here.
    <i>Next step I want send those results to target system which is legacy. If that is success</i>
    >>>You can make sure that message is recieved by legacy system. Because legacy systems like File systems will not support Application Acknowledgement. So here you can go with Transport Acknowledgement.
    From where will get Success messages like (current date etc) are you planning to take XI system date.. If so you can get this. And you can send the message to SQL.
    <i>If it fails any stage like while selecting data from interface control table which is SP1/ SP2 It should give error message back to XI(output parameters). XI is going to send Alerts/Mails to respective interface owners.</i>
    >>>For application errors like SP2 error etc, you need to get the Error Response from stored procedure itsel.
    Second option is you can go with Adapter Alerting, whenever any error in the Sender JDBC adapter.
    Anyway design/requirement should be perfect, before start the process here...
    Regards,
    Moorthy

Maybe you are looking for

  • What is default database listener port number

    Running emca script requested for database listener port number. Where do I get this information from.

  • Database refresh from cold backup and hotbackup.

    How can we perform Database refresh from cold backup and hotbackup?

  • Problem in Error Message

    Hi Abappers, I have coded as LOOP AT lt_toa01 INTO ls_toa01.   INSERT INTO toa01 VALUES ls_toa01.   IF sy-subrc NE 0.     MESSAGE ID 'ZIXMESSAGE' TYPE 'E' NUMBER '000'.     CONTINUE.     WRITE:/ ls_toa01-mandt,             ls_toa01-sap_object,       

  • Looping video or audio slide

    I have been trying to "loop" a video file to play over and over and am having no luck. I thought I could follow instructions, but eveidently I'm retarded or the instructions are not correct. I also would like to loop an entire presentation without fi

  • Publish a Dreamweaver designed Site to a Wordpress hosted Domain

    Hi everyone, I'm very new to this, and been relying on some amazing YouTube tutorials out there! I've come across a slight problem. I brought a domain name using Wordpress.com and have a rough blog there - very messy. I've since redesigend the entire