db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sivagururaja <sivagurur...@gmail.com>
Subject Re: Need stored procedure help!
Date Thu, 16 Dec 2010 06:04:54 GMT

Thanks Mr.Knut Anders,

I have one more doubt. Here is an example,
public class MyProcedures { 
public static void insert(String name)
    {
        try
        {
            Connection con =
DriverManager.getConnection("jdbc:default:connection");
            PreparedStatement ps = con.prepareStatement("INSERT INTO
TABLENAME(FIRSTNAME) VALUES(?)");
            ps.setString(1, name);
            ps.executeUpdate();

            ps.close();
            con.close();
        }
        catch (Exception ex)
        {
        }
    }
}

CREATE PROCEDURE PROC (IN firstName varchar(50))
    EXTERNAL NAME 'MyProcedures.insert'
    LANGUAGE JAVA
    MODIFIES SQL DATA
    PARAMETER STYLE JAVA 

Then i have to call the SP,
CallableStatement cst = conn.prepareCall("call insert(?)");
for(String name : names)
{
   cst.setString(1, name);
   cst.executeUpdate();
   cst.clearParameters();
}
cst.close();

Even though i am using PreparedStatement in my procedure, i am initializing
the PreparedStatement again and again by calling executeUpdate(). Which
means it's equivalent to use the java.sql.Statement. If 'm not wrong, how
come we achieve the performance. 

I have two options. I have to pass the names Object to my procedure and
insert all the names by iterating the same or I can use the above for-each
loop.
Now can you please tell me, which one you prefer in terms of efficiency.

Thanks in advance.
-- 
View this message in context: http://old.nabble.com/Need-stored-procedure-help%21-tp30462437p30470327.html
Sent from the Apache Derby Users mailing list archive at Nabble.com.


Mime
View raw message