SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict ArunB's Avatar
    Join Date
    Jun 2008
    Location
    Hyderabad
    Posts
    252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Problem while executing Stored procedure

    Code Java:
    CallableStatement callableStatement = null;
    callableStatement = conn.prepareCall("{call sp_Test1 (?, ?)}");
    callableStatement.setString( 1, '123456' );
    callableStatement.setString( 2, '654321' );
    boolean bExecuted = callableStatement.execute(); // Returning false.
     
    /*
    In SQL Server, >>>   execute sp_Test1 '123456', '654321' is returning Result set.
    */

    Executing the Stored procedure in SQL Server will return a ResultSet (About 100 records, 1 column per record).

    When I execute the stored procedure in Java, execute method is returning false.

  2. #2
    SitePoint Wizard silver trophy rushiku's Avatar
    Join Date
    Dec 2003
    Location
    A van down by the river
    Posts
    2,056
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    callableStatement.setString( 1, '123456' );

    Should be

    callableStatement.setString( 1, "'123456'" );

    Without the double quotes, this won't even compile...

  3. #3
    SitePoint Addict ArunB's Avatar
    Join Date
    Jun 2008
    Location
    Hyderabad
    Posts
    252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually the data is stored in variables( data is coming from client ).

    I am binding it to the prepared call using the function setString. Even tried to add double quotes there. But it didn't solved the problem, still the execute method is returning false.

    And callableStatement.getResultSet() is returning null. So, the next() function of the resultant ResultSet is throwing NullPointerException.

    In the example provided at Java Almanac web site,

    Code Java:
    // Call a procedure with one IN parameter
    cs = connection.prepareCall("{call myprocin(?)}");
     
    // Set the value for the IN parameter
    cs.setString(1, "a string");
     
    // Execute the stored procedure
    cs.execute();

    we doesn't need to use any quotes inside the double quotes.

    Is there anyway to get the trace of the error? Even getWarnings() is also returning null.

  4. #4
    SitePoint Wizard silver trophy rushiku's Avatar
    Join Date
    Dec 2003
    Location
    A van down by the river
    Posts
    2,056
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    Something is not working the way you think it should (obviously), have you tried outputting the statement? Try logging cs.toString() before and after the setString()s to see if the statement is correct.

  5. #5
    SitePoint Addict ArunB's Avatar
    Join Date
    Jun 2008
    Location
    Hyderabad
    Posts
    252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Also, I am trying with hard-coded strings. And toString() is returning correct string. Still returning false.


Bookmarks

Posting Permissions

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