Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2004
    Posts
    14

    Unanswered: Oracle Stored Procedure in Java

    I am try to write a stored procedure which is to written using java and then loaded into oracle. What this stored procedure does is insert some values into an oracle table. Here is a piece of code that i have tested before doing the whole real thing. But the stored procedure compiled, loaded into oracle without problems. Once the stored procedure is executed, it does nothing.

    Heres the code -

    import java.sql.*;
    import oracle.jdbc.driver.*;

    public class test{
    public static void insert()
    {
    Connection cn = null;
    PreparedStatement ps = null;
    String sql ="INSERT INTO Testing.test VALUES ('JEFF')";
    try{
    cn = new OracleDriver().defaultConnection();
    ps.execute(sql);
    ps.close();
    cn.commit();
    cn.close();
    }catch(Exception e){

    }
    }
    }

    Here is the table structure in Oracle 9i -

    Name Null? Type
    ------------------------------ --------

    USER NOT NULL CHAR(12)

    Hope u guys can help me out.

  2. #2
    Join Date
    Dec 2003
    Location
    Noida, India.
    Posts
    171
    preparedstatement is not initialiazed?
    Oracle can do wonders !

  3. #3
    Join Date
    Dec 2003
    Location
    Noida, India.
    Posts
    171

    Re: Oracle Stored Procedure in Java

    this is what you do..

    Code:
    ps = cn.prepareStatement(sql);
    ps.executeUpdate();
    cn.commit();
    cn.close();
    Oracle can do wonders !

  4. #4
    Join Date
    Feb 2004
    Posts
    18

    Re: Oracle Stored Procedure in Java

    Originally posted by vyruzj
    I am try to write a stored procedure which is to written using java and then loaded into oracle. What this stored procedure does is insert some values into an oracle table. Here is a piece of code that i have tested before doing the whole real thing. But the stored procedure compiled, loaded into oracle without problems. Once the stored procedure is executed, it does nothing.

    Heres the code -

    import java.sql.*;
    import oracle.jdbc.driver.*;

    public class test{
    public static void insert()
    {
    Connection cn = null;
    PreparedStatement ps = null;
    String sql ="INSERT INTO Testing.test VALUES ('JEFF')";
    try{
    cn = new OracleDriver().defaultConnection();
    ps.execute(sql);
    ps.close();
    cn.commit();
    cn.close();
    }catch(Exception e){

    }
    }
    }

    Here is the table structure in Oracle 9i -

    Name Null? Type
    ------------------------------ --------

    USER NOT NULL CHAR(12)

    Hope u guys can help me out.


    The prepared statement is not initialised, hence your code is throwing a null pointer exception which is being caught and not doing further execution. You have to initialise the ps as follows:
    ps = cn.prepareStatement(sql);
    ps.execute();
    ps.close();

  5. #5
    Join Date
    Jan 2004
    Posts
    14
    Thank for your input guys. Yup, the thing is working fine now. Thanks!

Posting Permissions

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