Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2003
    Posts
    33

    Unanswered: Wanna create a oracle procedure in Java

    Hi

    I am creating a stored procedure in java (Not calling the existing procedure....creating a new procedure)

    My Class looks like this:

    import java.sql.*;
    public class sqlTest
    {
    public static void main(String[] args)
    {
    System.out.println("Hello World!");
    try
    {
    Connection conn = null;
    Class.forName("oracle.jdbc.driver.OracleDriver");
    conn =DriverManager.getConnection("jdbcracleci8:@ottold","ottuser2","ottuser2");

    Statement st = null;
    boolean isExecuted = false;
    String plSqlStatment = "create or replace procedure sriram \n"+
    "as\n"+
    "no number;\n"+
    "begin\n"+
    "select count(*) into no from departmentassignment;\n"+
    "end;\n"+
    "/";

    System.out.println("--Query--");
    System.out.println(plSqlStatment);
    st = conn.createStatement();
    isExecuted = st.execute(plSqlStatment);

    System.out.println("--Package created--" + isExecuted);
    }
    catch(Exception e)
    {
    System.out.println("--Exception created --"+e);
    }
    }
    }

    Compiled successfully
    when i run this following messages:

    Hello World!
    --Query--
    create or replace procedure sriram
    as
    no number;
    begin
    select count(*) into no from departmentassignment;
    end;
    /
    --Package created--false

    Whats the problem...
    Last edited by kondaoracle; 10-03-03 at 08:56.

  2. #2
    Join Date
    Feb 2004
    Posts
    1

    Semicolon

    I had a similar problem, turned out Java doesn't tolerate semi-colons in SQL queries. One can only execute a single statement. So in your query the semi-colon and slash need to go.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •