Results 1 to 3 of 3
  1. #1
    chizbox is offline Member
    Join Date
    Feb 2010
    Location
    Philippines
    Posts
    20
    Rep Power
    0

    Default Calling Stored Procedures from oragle10g

    please help me with my code i cant seem to run it from java
    i have google sample codes and try using it but it dosnt work

    String sql = "call pckg_insert_event.trakout('" + lt.getLotClass() + lt.getLotNo() +"','"+lt.getDevice()+"',"+ lt.getWaferQty() + "," + lt.getShipQty() + ",'"+ lt.getInvoiceNo() + "')";

    CallableStatement cStmt = conn.prepareCall(sql);


    The SQL statement is this
    call pckg_insert_event.trakout('AJ1234567890','ORMIC-012',2,2008,'1234567890')

  2. #2
    travishein's Avatar
    travishein is offline Senior Member
    Join Date
    Sep 2009
    Location
    Canada
    Posts
    684
    Rep Power
    5

    Default

    I think the sql statement needs to be enclosed in "{" and "}". Its some kind of JDBC escape notation.

    as,

    Java Code:
    String sql = "{ call pckg_insert_event.trakout('" + lt.getLotClass() + lt.getLotNo() +"','"+lt.getDevice()+"',"+ lt.getWaferQty() + "," + lt.getShipQty() + ",'"+ lt.getInvoiceNo() + "') }";
    Though, CallableStatement extends PreparedStatement. I think its better to make use of positional parameters where possible, to avoid problems if the string variable values contain single quotes and needing to escape these, or to prevent sql injection attacks, if it is ever possible one of these string values could be entered from an end user form input field.

    Java Code:
    String sql = "{ call pckg_insert_event.trakout(?, ?, ?, ?, ?) }";
    
    CallableStatement cStmt = conn.prepareCall(sql);
    cStmt.setString(1, lt.getLotClass() + lt.getLotNo() );
    cStmt.setString(2, lt.getDevice());
    cStmt.setInt     (3, lt.getWaferQty());
    cStmt.setInt     (4, lt.getShipQty());
    cStmt.setString(5, lt.getInvoiceNo());
    
    cStmt.execute();

  3. #3
    chizbox is offline Member
    Join Date
    Feb 2010
    Location
    Philippines
    Posts
    20
    Rep Power
    0

Similar Threads

  1. Stored Procedures
    By geeta_ravikanti in forum JDBC
    Replies: 1
    Last Post: 04-22-2008, 02:34 AM
  2. Calling SQL Server stored procedures
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-07-2008, 08:40 AM
  3. Stored Procedures with java
    By Albert in forum JDBC
    Replies: 4
    Last Post: 06-08-2007, 05:59 AM
  4. stored procedures in Hibernate
    By Alan in forum JDBC
    Replies: 2
    Last Post: 05-31-2007, 04:49 PM

Posting Permissions

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