Topic
  • 3 replies
  • Latest Post - ‏2013-12-20T15:17:36Z by MaryMuraski
TheBrave SamWise
TheBrave SamWise
2 Posts

Pinned topic Call Informix stored procedure in java

‏2013-12-19T10:01:23Z |

I have a stored procedure.. I want to call the procedure in java. However, the result did not come out..

Error

java.lang.NullPointerException

How actually to call informix stored procedure in java. Please help me.. This is my code examples..

 

Stored procedure

create procedure tryBaru_Procedure(v_name varchar(50),v_city varchar(20),out v_id int)

select id
into v_id
from tryBaru
where name=v_name;

update tryBaru
set city=v_city
where id=v_id;
end procedure;

Java

public class TryBaru_Controller {


Connection conn;
DBConnection dbConn = new DBConnection();

public tryBaru p(tryBaru tryje) throws Exception
{
    conn = dbConn.getConnection();

    //prepare call store procedure
    CallableStatement cs = conn.prepareCall("{ call tryBaru_Procedure(?,?,?) }");


    cs.setString(1, tryje.getName());
    cs.setString(2, tryje.getCity());
    cs.registerOutParameter(3, Types.INTEGER);


     cs.executeQuery();
     tryje.setId(cs.getInt(3));
    cs.close();
    conn.close();

    return tryje;
}
}

Main

public static void main(String[] args){
    // TODO Auto-generated method stub

    TryBaru_Controller tbc = new TryBaru_Controller();
    tryBaru tb = new tryBaru();

    String name1 = "Faridah";
    String city1 = "Johor";

    tb.setName(name1);
    tb.setCity(city1);
    try {
        tbc.p(tb);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    System.out.println(tb.getName());
    System.out.println(tb.getCity());
    System.out.println(tb.getId());

}

 

  • MaryMuraski
    MaryMuraski
    7 Posts

    Re: Call Informix stored procedure in java

    ‏2013-12-19T13:20:04Z  

    What version of Informix JDBC are you using and the version of JDK.  It would be nice to know the version of Informix server you are using as well.

  • TheBrave SamWise
    TheBrave SamWise
    2 Posts

    Re: Call Informix stored procedure in java

    ‏2013-12-20T02:36:52Z  

    What version of Informix JDBC are you using and the version of JDK.  It would be nice to know the version of Informix server you are using as well.

    I'm using Informix Developer Edition Version  12.10TC2DE.

    For JDBC I just take the driver from folder C:\Program Files\IBM Informix Software Bundle\jdbc\lib\ifxjdbc.jar.. Is it right, or I need to download the driver??

    I'm not using JDK, just using JRE Version  1.7.0_45. Did I need to use JDK to run the code??

    Actually I'm newbie to informix. I'm exploring Informix for learning purpose. I run the code with oracle database and it's worked. but error with informix. 

    Updated on 2013-12-20T02:54:10Z at 2013-12-20T02:54:10Z by TheBrave SamWise
  • MaryMuraski
    MaryMuraski
    7 Posts

    Re: Call Informix stored procedure in java

    ‏2013-12-20T15:17:36Z  

    I checked the version of JDBC that comes with the servers and it is limited to creating UDR for the servers.

     

    I would download the full version of JDBC 4.1 then use the ifxjdbc.jar this it contains.  I am not sure if the java codes needs to be recompiled.  If you encounter a problem I would recompile the applications

     

    HTH