Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2012
    Posts
    4

    Unanswered: Call Informix stored procedure in java

    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
    Code:
    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
    Code:
    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
    Code:
    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());
    
    }

  2. #2
    Join Date
    Sep 2011
    Location
    Pont l'Abbé, Brittany, France
    Posts
    381
    Provided Answers: 1
    Hi,

    I am not a java specialist ( at all ), but the right syntax to invoke an Informix stored procedure is
    Code:
    EXECUTE PROCEDURE procedure_name(args list,.....)
    CALL will not work

    Hope this helps and merry Christmas!

    Eric

Tags for this Thread

Posting Permissions

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