Results 1 to 9 of 9
  1. #1
    Join Date
    May 2013
    Posts
    10

    Unanswered: Passing Date parameter calling DB2 Stored Procedure though java code

    Hello,

    I am tring to pass Date parameter in calling DB2 stored procedure through java code and getting following syntax error

    "The method setDate(int, Date) in the preparedStatement si not applicable for arguement(int, Date)"

    at line cstmt.setDate(2, dt);

    My first parameter type is STRING and Seoncd prameter type is DATE in db2 stored procedure.



    Actually code is not compiling due to syntax error

    CallableStatement cstmt = null;
    Connection con = null;
    DateFormat dateFormat = new SimpleDateFormat("YYYY/MM/DD");
    Date dt = new Date();


    con = getDB2Connection();
    cstmt = con.prepareCall("CALL MYSCHEMA.MYPROC(?, ?, ?, ?)");
    cstmt.setString(1,"STRINGVAL1");
    [COLOR="Red"]cstmt.setDate(2, dt);[/COLOR]

    cstmt.registerOutParameter(3, Types.INTEGER);
    cstmt.registerOutParameter(4, Types.VARCHAR);

    //calling stroed procedure
    cstmt.executeQuery();

    int returnCode = cstmt.getInt(3);
    String msg = cstmt.getString(4);

    System.out.println(" code returned from stored procedure = " + returnCode);
    System.out.println(" message returned from stored procedure = " + msg);


    cstmt.close();


    HOW TO PASS DATE PARAMETER THOUGH JAVA CALLING DB2 STORED PROCEDURE PLEASE.
    Last edited by aradhya; 05-06-13 at 12:02.

  2. #2
    Join Date
    Jan 2003
    Posts
    4,292
    Provided Answers: 5
    Is dt java.util.Date or java.sql.Date?

    Andy

  3. #3
    Join Date
    May 2013
    Posts
    10
    Not sure, does it make different in java.util.Date or java.sql.Date?

  4. #4
    Join Date
    Jan 2003
    Posts
    4,292
    Provided Answers: 5
    Yes it does.

  5. #5
    Join Date
    May 2013
    Posts
    10
    In DB2 stored procedure has DATE datatype, now as java developer i have to decide how would i pass date from Java program to call DB2 stored procedure,

    Now in above situation, which one should be the preference?

  6. #6
    Join Date
    Jan 2003
    Posts
    4,292
    Provided Answers: 5
    That does not matter. You are using JDBC setDate method and it wants a java.sql.Date for its 2nd parameter. So that is what you need to use.

    Andy

  7. #7
    Join Date
    May 2013
    Posts
    10
    Thanks a lot Andy, let me try that way.

    Aradhya

  8. #8
    Join Date
    May 2013
    Posts
    10
    I tried passing java.sql.Date as follows,

    private static java.sql.Date getCurrentDate() {
    java.util.Date today = new java.util.Date();
    return new java.sql.Date(today.getTime());


    cstmt.setDate(2,getCurrentDate());

  9. #9
    Join Date
    Jul 2009
    Location
    NY
    Posts
    963

    Thumbs down

    Quote Originally Posted by aradhya View Post
    Hello,

    I am tring to pass Date parameter in calling DB2 stored procedure through java code and getting following syntax error

    "The method setDate(int, Date) in the preparedStatement si not applicable for arguement(int, Date)"

    at line cstmt.setDate(2, dt);

    My first parameter type is STRING and Seoncd prameter type is DATE in db2 stored procedure.



    Actually code is not compiling due to syntax error

    CallableStatement cstmt = null;
    Connection con = null;
    DateFormat dateFormat = new SimpleDateFormat("YYYY/MM/DD"); Date dt = new Date();
    .................................................. ........................
    Let see the next 2 simple queries:

    Code:
    select date('2013/05/07')
    from sysibm.sysdummy1
    
    The syntax of the string representation of a datetime value is incorrect.  
    SQLCODE = -180
    
    select date('2013-05-07')
    from sysibm.sysdummy1
    
    Correct Syntax
    Lenny

Posting Permissions

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