How to execute a PL/SQL in JAVA

I know how to execute a store procedure in PL/SQ. But how to execute a PL/SQL in JSP or other JAVA application?
Thank you!

<BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by Chin Chia Liang ([email protected]):
I know how to execute a store procedure in PL/SQ. But how to execute a PL/SQL in JSP or other JAVA application?
Thank you!<HR></BLOCKQUOTE>
You should use CallableStatement.
import java.sql.*;
class StoreProc
public static void main (String args [])
throws SQLException {
try {
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
Connection conn =DriverManager.getConnection ("jdbc:oracle:thin:@testing:1521:test1", "scott", "tiger");
//create procedure and call it in java (testproc)
CallableStatement cstmt = conn.prepareCall("{call testproc(?,?)}");
cstmt.setString(1, "teststore");
(2, "testagain");
cstmt.executeUpdate();
cstmt .close();
conn.close();
catch(SQLException e)
System.out.println("SQLException caught: " + e.getMessage()+" "+e.getErrorCode());
null

Similar Messages

  • How to execute a SELECT statement  in java??

    Hello !!
    In my java program , i need to delete a record of number X, so
    i accept the number X from the keyboard
    Then before deleting it
    i want the program to show me the name, age of the record which has the number X
    How to do this

    hello kylas
    actually i didnt get why this program example?? wats
    its executing ??? Look at reply #3 in your other thread:
    http://forum.java.sun.com/thread.jspa?threadID=713289&messageID=4126346
    Notice the similarity? You've now asked "How to delete a record in Java" and "how to execute a select statement in java". You may have noticed that, aside from the SQL and the call to execute and executeUpdate (for delete) it's the same code. This is because you don't so much do these things in Java, you do them in SQL. The Java code simply asks the Driver to execute whatever SQL you write. So, I really hope your next post isn't "how do I execute an UPDATE statement in Java".
    Good Luck
    Lee

  • How to execute Dos Command 'Pause' from Java ?

    How to execute Dos Command 'Pause' from Java ?
    I have read the article in javaworld for Runtime.exec() anomalies.
    Can someone please give an insight on this?

    Thanks Buddy!
    That was very useful. Even though its a simple
    solution, I never thought about that.Bullshit! Reread reply #7 of http://forum.java.sun.com/thread.jspa?threadID=780193

  • How to execute unix shell script from Java ...

    Hi,
    Anyone know how to execute unix shell script from Java?
    Suppose I have several shell scripts written in perl or tcl or bash.
    I just want to catch the output of that script.
    Is there any ready to use module/object for this?
    Please let me know, this is quite urgent for my study assigment.
    Thanks in advance,
    Regards,
    me

    Look up Runtime.exec()

  • How to execute a script(.sql) file from a PL\SQL procedure

    I would like to know how to execute a .sql file from a stored procedure and the result of it should update a table. My .sql file contains select statements.

    Hi!
    just go through the following piece of code -
    SQL> ed
    Wrote file afiedt.buf
      1  declare
      2    str varchar2(200);
      3  begin
      4    str := '@C:\RND\Oracle\Misc\b.sql';
      5    execute immediate(str);
      6* end;
    SQL> /
    declare
    ERROR at line 1:
    ORA-00900: invalid SQL statement
    ORA-06512: at line 5ORA-00900: invalid SQL statement
    Cause: The statement is not recognized as a valid SQL statement. This error can occur if the Procedural Option is not installed and a SQL statement is issued that requires this option (for example, a CREATE PROCEDURE statement). You can determine if the Procedural Option is installed by starting SQL*Plus. If the PL/SQL banner is not displayed, then the option is not installed.
    Action: Correct the syntax or install the Procedural Option.
    Regards.
    Satyaki De.

  • How to execute a .exe file in java(Jsp) without using a process ???

    Hi All ,
    How to execute a .exe file in Jsp without using a process ??? ...
    Is it Possiable ????

    itsdhanasaraa wrote:
    But as this a web application ... By using Runtime i'm getting some probs ..
    Let me guess, you want your web application to run a program on the client and to your surprise that's not working?
    Ain't gonna happen.
    its taking more time to execute .... that's y is there any other option to execute .exe file other than Runtime.getRuntime().exec("filename");Write proper English and you may be taken more seriously.
    1) it's not "taking more time to execute", whatever that's supposed to mean.
    2) there's no other way to execute something. Not that you should every use even that way anyway
    3) whenever you start thinking of executing external programs from Java, start thinking of not using Java in the first place.

  • How to execute a shell command in java?

    here, my environment is redhat 7, jdk 1.5.
    i don't know how to use the shell command in java.
    i want to use this function:
    #include <stdlib.h>
    int system(const char * string);
    please give me some ideas. and Thank you so much if coming with a little demo.

    i know i should use JNI. because i have to use C lib.
    but i have already use JNI to wrapper the original code the cpp code and java code is :
    //: appendixb:UseObjImpl.cpp
    //# Tested with VC++ & BC++. Include path must
    //# be adjusted to find the JNI headers. See
    //# the makefile for this chapter (in the
    //# downloadable source code) for an example.
    #include <jni.h>
    #include <stdlib.h>
    extern "C" JNIEXPORT void JNICALL
    Java_UseObjects_changeObject(
    JNIEnv* env, jobject, jobject obj) {
    jclass cls = env->GetObjectClass(obj);
    jfieldID fid = env->GetFieldID(
    cls, "aValue", "I");
    jmethodID mid = env->GetMethodID(
    cls, "divByTwo", "()V");
    int value = env->GetIntField(obj, fid);
    printf("Native: %d\n", value);
    env->SetIntField(obj, fid, 6);
    env->CallVoidMethod(obj, mid);
    value = env->GetIntField(obj, fid);
    system("preprocess -path sha.c");
    printf("Native: %d\n", value);
    } ///:~
    //: appendixb:UseObjects.java
    // From 'Thinking in Java, 2nd ed.' by Bruce Eckel
    // www.BruceEckel.com. See copyright notice in CopyRight.txt.
    class MyJavaClass {
    public int aValue;
    public void divByTwo() { aValue /= 2; }
    public class UseObjects {
    private native void
    changeObject(MyJavaClass obj);
    static {
    // System.loadLibrary("UseObjImpl");
    // Linux hack, if you can't get your library
    // path set in your environment:
    System.load(
    "/root/jproj/UseObjImpl.so");
    public static void main(String[] args) {
    UseObjects app = new UseObjects();
    MyJavaClass anObj = new MyJavaClass();
    anObj.aValue = 2;
    app.changeObject(anObj);
    System.out.println("Java: " + anObj.aValue);
    } ///:~
    i modify this two file which is from TIJ-2edition.
    the output is
    Native: 2
    Native: 3
    Java: 3
    but what i want to be executed "preprocess -path sha.c" does not work.
    i have change the command to, such as "df", "ls" etc. but none of them works
    please help me.

  • How to execute external  spawned process using  java

    Hi,
    I am executing PGP from command line using java.
    For adding the public key I use Runtime object like this
    Runtime rt = Runtime.getRuntime();
    Process process = rt.exec("pgp -ka "+"d:/Mangesh/pubkey/sandy.asc "+"C:/PROGRA~1/NETWOR~1/PGPNT/keyrings/pubring.pkr");PGP is executing this but inbetween it asked for confirmation "Do you want to add public key (y/n)"
    I am providing data to process this way:
    PrintWriter pw = new PrintWriter(new OutputStreamWriter( process.getOutputStream()));
    pw.write('y');
    pw.flush();But after this their is no execution from PGP and console remains until I closed it.
    PGP is waiting for ENTER KEY
    How can I provide ENTER KEY from java
    This is right method ??? or any other options are available??
    I am awaiting for your valuable suggestions .
    Regards
    Man479

    On Windows the "enter key" consists of two characters: carriage return and a line feed (\r\n). You may have to send both. If that doesn't work, pgp is not reading the reply through stdin, only through the console, and there's no way to pass the 'y' to it through Java.

  • How to execute any cmd command from java application?

    Hi all,
    How to execute or call any command of cmd from java application??
    Is there any method to do so??
    Or, is it possible to do it using Runtime.exec() ??? And if so, how to use it, please explain with ab example...
    I'll highly appreciate....
    Thank you.

    If google would be the best option, then I would not be on Sun's forums and I would not have asked experts like you, sir !! :-)
    Neway, I got the solution from PhHein !!
    Good link indeed..
    Cheers..

  • How to execute an external file in java ?

    How to execute an external file , where the file name of the external file is in unicode character. (i,e, may be in Chinese character).

    Process p = Runtime.getRuntime().exec("/path/to/executable");
    This is write. But my question is while the file name is in Chinese font.
    It means while a file name is in Chinese font or any unicode character that are supported by window but not in the command prompt. In this case the file name is changed to ??????.doc like.
    So, while trying to execute this it shows File not found message.

  • How to execute procedure in SQL Worksheet ?

    Hi, anybody know, how I can execute procedure here?
    I try EXEC sec_roles, EXEC security_admin.sec_roles, EXECUTE - there is a SQL statement error. When I use CALL - there is no such procedure (I have execute previleges).
    Although in SQLPlus EXEC works, but there are problems with standard SQL commands (all of them returns "2" no matter what content is).
    Any ideas?
    Regards
    Krzysztof

    exec procedure(parameters) is a sql plus (and a few others) shortcut for
    BEGIN
       procedure(parameters);
    END;So try that then pressing/clicking whatever it is in sql worksheet that makes a statement run.
    Note that if your procedure has parameters defined as OUT or IN OUT, you will need to supply a variable to accept the returned value(s).
    John

  • How to execute unix command from the Java program running on Windows

    Hello,
    I need to
    1. Execute a unix shell script from a Java program running on the Windows.
    2. I also need to capture the output of this shell script in my program.
    Please suggest me how to achieve this.
    Thanks in Advance.

    Hi...
    Something is missing here
    If you want to execute a shell script in windows that not posible unless you find or develop a unix shell script parser for windows.
    But if you are trying the execute a unix shell script on a remote unix computer from your java program running on a windows platform you can do that by logging on to the UNIX terminal which is running on port 23 I think.
    You can test this using telnet tool on windows
    just type on command prompt
    telnet <ip of the unix pc> <port number this case 23>
    you should get the unix terminal. If that works you can do the same through java or you can directly conect to port 23 of that pc using sockets that way your program will be platform independant

  • How to execute a Unix Command in java

    Hi, Iam trying to execute a unix command on Sun Solaris by passing that command to a java program. How can I achieve this?
    Thanks in advance.

    Have a look at the javadoc around the Runtime.exec() method. If the command is a shell command then you might have to execute a shell as well as the command.
    For example, if you wanted to run a unix command 'ls -l > output.txt' the you might have to pass the following string into the exec() method,
    "/bin/sh ls -l > output.txt'

  • How to execute a .cmd file in java

    I can execute an .bat or a .exe file.
    But .cmd file is not getting executed in java.
    Pls tell me how to do this

    You can solve this problem by using the following method:
      private String[] getEnvironmentVariables() {
        final Map<String, String> env = System.getenv();
        final String[] result = new String[env.size()];
        final StringBuilder buf = new StringBuilder(100);
        int i = 0;
        for (Entry<String, String> e : env.entrySet()) {
          buf.setLength(0);
          result[i++] = buf.append(e.getKey()).append('=').append(e.getValue()).toString();
        return result;
      }You just have to execute your command like this now:
    Runtime.exec("cmd /C " + getMyCommand(), getEnvironmentVariables(), getMyExecDirectory());The reason why "start" didn't work is, that it is a command executed in a shell, thus you need "cmd /C" to execute start in the cmd. So you can do this as well:
    Runtime.exec("cmd /C start " + getMyCommand(), getEnvironmentVariables(), getMyExecDirectory());If you want to to execute "myCommand" in an own process.
    Kind Regards,
    Stefan Schubert

  • How to execute the ldapsearch command by java class in linux os?

    hi,all
    I want to query the users by ldapsearch command. I call the command in my java class. In windows, It work well. But in linux , there haven't any result. My test program is following:
    ===============
    import java.util.*;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.io.LineNumberReader;
    public class test{
    public static Vector queryAllUser(){
    try{
    Vector v=new Vector();
    String cmdquery="ldapsearch -h localhost -b\"dc=metasphere,dc=com\" \"uid=*\" uid ";
    //String cmdquery="ls -la";
    Process process=Runtime.getRuntime().exec(cmdquery);
    System.out.println("cmdquery:"+cmdquery);
    InputStreamReader ir=new InputStreamReader(process.getInputStream());
    LineNumberReader input = new LineNumberReader (ir);
    System.out.println("input="+input);
    String line;
    while ((line = input.readLine ()) != null){
    System.out.println("Line:"+line);
    if(line.startsWith("uid")){
    String temp=line.substring(line.indexOf(":")+1,line.length());
    v.add(temp);
    return v;
    }catch(Exception e){
    e.printStackTrace();
    System.out.println("runtime error:"+e.getMessage());
    return null;
    public static void main(String argv[]){
    Vector v=queryAllUser();
    for(int i=0;i<v.size();i++){
    System.out.println((String)v.get(i));
    ================
    In fact, when I execute the command: ldapsearch -h localhost -b"dc=metasphere,dc=com" "uid=*" uid
    in linux prompt, the screen show the results:
    version: 1
    dn: uid=toppymgt,dc=metasphere,dc=com
    uid: toppymgt
    dn: uid=qutao,dc=metasphere,dc=com
    uid: qutao
    dn: uid=zz,dc=metasphere,dc=com
    uid: zz
    dn: uid=z,dc=metasphere,dc=com
    uid: z
    dn: uid=admin,dc=metasphere,dc=com
    uid: admin
    dn: uid=alan,dc=metasphere,dc=com
    uid: alan
    dn: uid=misssixty,dc=metasphere,dc=com
    uid: misssixty
    dn: uid=channelv,dc=metasphere,dc=com
    uid: channelv
    What's reason? Please help me. Thx.

    If there have a bugs in Linux OS. Please help me!

Maybe you are looking for

  • Payables Trial Balance

    Hi, We are on 11.5.10, we have 2 questions on using XML publisher with AP trial Balance.. 1. Even if we run the report for a specific supplier the text output is only a page, but the XML output is so huge it cannot be save on our desktop... i have se

  • In delivery - Header- Administration-Sales office is blank.

    Hi Gurus Please help as I am not getting entries updated in LIKP-VKBUR (Sales office in case of deliveries). So In every Delivery--Header-Administration--Sales Office is blank. I have checked the following: 1. Sales office entries are maintained in C

  • Creative mp3 reliabili

    do all these issues on this message board not tell you something? i have had 2 creative zen 4gb mp3 players and both have gone wrong in a couple of weeks, very little actual direct support too. i can definitly say that i wont be getting another one!

  • Macbook Pro 2010 will not start up properly

    My Macbook Pro suddenly stopped responding to my actions, which it had never done before (ex. my music on itunes would stop playing without me presseing anything). I shut it down forcefully. At first it did not turn on and was making these weird nois

  • Select column 1 into two column from same table

    Dear Sir I have a data like studid makr tottal credit total average mark semester 251; 249.84; 41; 6.09; 1 106; 285.32; 42; 6.79; 1 285; 263.88; 38; 6.94; 1 251; 202.40; 28; 7.23; 2 106; 293.20; 39; 7.52; 2 285; 228.14; 39; 5.85; 2 I want to select a