Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: Oracle Stored Procedure execution in java

  1. #1
    Junior Member
    Join Date
    Jun 2020
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Oracle Stored Procedure execution in java

    Hi All

    I am having oracle stored procedure which does not have any out parameter in it. I want to execute and need to take the output from that procedure and display it in UI using Java. I have googled but i am getting any sample codes to get out value when out parameter not defined in oracle stored procedure. Could you please help us to resolve this issue. is there any way to get the output in java.

    Sample procedure:

    CREATE OR REPLACE PROCEDURE PROC1
    AS BEGIN
    SELECT AMOUNT INTO amnt FROM INVOICE WHERE INVOICE_NR = invoicenr;
    END;

    Thanks
    Krishnan

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Oracle Stored Procedure execution in java

    Do you have the java code for database communications?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Jun 2020
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Oracle Stored Procedure execution in java

    Yes i am having database connection codes and i can able to execute the stored procedure using callable statement. After executing that i can't able to take results of that procedure.


    import java.sql.CallableStatement;
    import java.sql.Connection;
    import java.sql.SQLException;

    public class JDBCStoredProcedureWrite {

    public static void main(String[] args) {
    Connection con = null;
    CallableStatement stmt = null;


    try{
    con = DBConnection.getConnection();
    stmt = con.prepareCall("{call PROC}");

    stmt.execute();
    //Need to get output this execute statement

    }catch(Exception e){
    e.printStackTrace();
    }finally{
    try {
    stmt.close();
    con.close();
    } catch (SQLException e) {
    e.printStackTrace();
    }
    }
    }

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Oracle Stored Procedure execution in java

    take results of that procedure.
    Is there a method that returns a ResultSet?

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Jun 2020
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Oracle Stored Procedure execution in java

    I will get single some amount as output for this stored procedure. If i use executeQuery(), it is executing the query but in resultSet, i am not getting value. The same procedure i can able to execute in database and i can able to see result. whether we can take like this from oracle stored procedure. that is without out parameter definition whether we can take procedure results. I need to take output of procedure even Out parameter is not defined in oracle stored procedure.

    try{
    con = DBConnection.getConnection();
    stmt = con.prepareCall("{call PROC}");
     
    //Need to get output this execute statement
    ResultSet rs = stmt.executeQuery();
     
     
    }catch(Exception e){
    e.printStackTrace();
    }

  6. #6
    Junior Member
    Join Date
    Jun 2020
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Oracle Stored Procedure execution in java

    Does anyone having idea to solve this issue ?.

Similar Threads

  1. SQL stored procedure to a grid view
    By Rajeshkumar in forum What's Wrong With My Code?
    Replies: 0
    Last Post: April 25th, 2014, 04:22 AM
  2. how to make autocommit false in stored procedure execute() method
    By Suryaksty in forum What's Wrong With My Code?
    Replies: 1
    Last Post: September 25th, 2013, 09:57 AM
  3. Replies: 1
    Last Post: May 1st, 2011, 10:13 AM
  4. unable to view the result generated by stored procedure
    By najmudeenhaja in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 1st, 2010, 08:39 AM