Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Stored Procedures (what is it really used for?)

843859Apr 4 2008 — edited Apr 4 2008
So from a tutorial, I successfully created a stored procedure, stored it, and made code to use it. I think.
If I run my code, it seems to work fine, regardless of whether or not I have entered that stored procedure into the database.

Is my code suppose to work regardless? Is storing a procedure just meant to make my code, which repeats quite often, more efficient? Or are stored procedures created for different reasons? Are they there to let me run my java code from an sql query? I'm at my wits end trying to understand the significance of a stored procedure. I've posted my code, if it helps.

 public static void callSortTwo(Connection conn, CallList cl) {
        try {
            Timestamp ts = new Timestamp(System.currentTimeMillis() );
            System.out.println("Executed at: " + ts);
            String insert_query = "INSERT INTO SWEATY_BALLSAK.CALLS (" +
                    "beat," +
                    "call_descr," +
                    "priority," +
                    "date," +
                    "time," +
                    "call_num," +
                    "location," +
                    "status," +
                    "entry_id) " +
                    "VALUES(?,?,?,?,?,?,?,?,?)";
           
            PreparedStatement pstmt = conn.prepareStatement(insert_query);
           
            for (int counter = 0; counter < cl.getSize(); counter++) {
                String current_event[] = cl.getElementArray(counter);
               
                pstmt.setString(1,current_event[0]);
                pstmt.setString(2,current_event[1]);
                pstmt.setString(3,current_event[2]);
                pstmt.setString(4,current_event[3]);
                pstmt.setString(5,current_event[4]);
                pstmt.setString(6,current_event[5]);
                pstmt.setString(7,current_event[6]);
                pstmt.setString(8,current_event[7]);
                pstmt.setTimestamp(9, ts);
               
                pstmt.executeUpdate();
                }
        }
       
        catch(SQLException sqle_callSort) {
            System.out.println("SQL Exception" + sqle_callSort.getMessage() );
        }
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 2 2008
Added on Apr 4 2008
5 comments
334 views