createstatement vs preparestatement

Discussion in 'Java' started by [XaToA], Jul 27, 2003.

  1. [XaToA]

    [XaToA] Guest

    for the select queries (select * from table) what is better for use:
    Statement stmt = conection.createStatement();
    stmt.executeQuery(sql);

    or

    PreparedStatement stmt = conection.PrepareStatement(sql);
    stmt.execute();

    what is better for use in web applications?
    can you help me?

    for the updates and inserts y use PreparedStatements

    thanks
     
    [XaToA], Jul 27, 2003
    #1
    1. Advertising

  2. "[XaToA]" <> wrote in message
    news:bg174e$jm7io$-berlin.de...
    > for the select queries (select * from table) what is better for use:
    > Statement stmt = conection.createStatement();
    > stmt.executeQuery(sql);
    >
    > or
    >
    > PreparedStatement stmt = conection.PrepareStatement(sql);
    > stmt.execute();
    >
    > what is better for use in web applications?
    > can you help me?
    >
    > for the updates and inserts y use PreparedStatements
    >
    > thanks
    >
    >


    It depends on your usage. If you plan of executing your statement
    infrequently, you might want to consider the createStatement() approach. If
    you plan on executing that statement frequently, and would not want to incur
    the repeated cost of creating and compiling the statement, you may be better
    off using prepared statements.

    Best to benchmark your application in the environment it is expected to be
    used, and you will have a better idea.

    The performance differences vary based on many factors, but a 10:1 over
    1000s of operations (in favor of the prepared statement) in steady state is
    not uncommon. For fewer iterations it can get to 2:1 or even 1:3.

    HTH,


    --
    Shripathi Kamath
    NETAPHOR SOFTWARE INC.
    http://www.netaphor.com
     
    Shripathi Kamath, Jul 27, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. knightowl

    Memory leak with createStatement?

    knightowl, Feb 25, 2005, in forum: Java
    Replies:
    9
    Views:
    938
    Dimitri Maziuk
    Feb 25, 2005
  2. PrepareStatement

    , Jan 29, 2008, in forum: Java
    Replies:
    0
    Views:
    362
  3. PrepareStatement

    , Jan 29, 2008, in forum: Java
    Replies:
    7
    Views:
    7,542
    SNK111
    Apr 10, 2010
Loading...

Share This Page