What is the defference between Statement & PreparedStatement?

Tell me some features of both! I don't know what the defferences is between them!
Which should i use?

Hi,
A Statement object is obtained by calling createStatement on a Connection, which Provides methods to execute SQL commands. The PreparedStatement is a slightly more powerful version of a Statement.
Please refer, http://www.jguru.com/faq/view.jsp?EID=693 for the difference between the both.
Hope that helps.
Regards,
Senthil Babu
Developer Technical Support
SUN Microsystems
http://www.sun.com/developers/support/

Similar Messages

  • What is the different between statement and preparedstatement?

    hi,
    recently i have attended a telephonic interview. they asked me what is the different between statement and preparedstatement? and when u will use them? Hi! can any one say me the original difference??

    sorry dear,
    i am already shortlisted. and monday is my HR round.
    . Every 1 is not like u.
    So you have read the examples and explanations that you found when you googled, and you have read the javadoc and you still don't understand? And you are shortlisted? For what? I hope you won't do server programming.
    I will give you a few hints.
    Escaping of data
    Storing of dates
    Safer
    Faster

  • What is the defference between select single * from and select * from Where

    What is the defference between select single * from and select * from Where
    which is prefferable and best one.

    Hai,
    *Difference Between Select Single and Select * from table UpTo One Rows:*
    According to SAP Performance course the SELECT UP TO 1 ROWS is faster than SELECT SINGLE because you are not using all the primary key fields.
    select single is a construct designed to read database records with primary key. In the absence of the primary key, it might end up doing a sequential search, whereas the select up to 1 rows may assume that there is no primary key supplied and will try to find most suitable index.
    The best way to find out is through sql trace or runtime analysis.
    Use "select up to 1 rows" only if you are sure that all the records returned will have the same value for the field(s) you are interested in. If not, you will be reading only the first record which matches the criteria, but may be the second or the third record has the value you are looking for.
    The System test result showed that the variant Single * takes less time than Up to 1 rows as there is an additional level for COUNT STOP KEY for SELECT ENDSELECT UP TO 1 ROWS.
    The 'SELECT SINGLE' statement selects the first row in the database that it finds that fulfils the 'WHERE' clause If this results in multiple records then only the first one will be returned and therefore may not be unique.
    Mainly:  to read data from
    The 'SELECT .... UP TO 1 ROWS' statement is subtly different. The database selects all of the relevant records that are defined by the WHERE clause, applies any aggregate, ordering or grouping functions to them and then returns the first record of the result set.

  • What`s the defferences between DirectSoundCapture and JavaSound audio Captu

    I use JMF 2.1.1 API and get two audio devices in my pc. One audio device named DirectSoundCapture, the other named JavaSound audio Capture. For every audio devices, it has many audio formats. I want to study to record through MIC, But I don`t know which audio device listed above was MIC. and I want to know what`s the defferences between the two audio device. I am new to JMF. Thx. Bob

    I would imagine a lot of difference. First of all, DirectSound could be accelerated in hardware and would offer more features, better quality, etc. I'm not sure if JavaSound can use hardware the same way. I would choose to use DirectSound if possible.

  • What is the difference between Statement and PreparedStatement

    Hi
    What is the difference between Stement and PrepareStatement Other than PreCompilation and dynamic Parameters?
    Thanks in advance.
    Sekhar

    Most of the differences are either those, or consequences of those (such as better performance, greater security, and simpler use for PreparedStatement). Serious programmers should almost always use PreparedStatement.
    The only other thing I know of is trivial: you can get ResultSetMetaData from a PreparedStatement without actually executing a query.

  • What's the difference between "PreparedStatement" and "Statement"?

    What's the difference between "PreparedStatement" and "Statement"?
    Which is better??????

    Read the docs for the two classes. The differences are apparent there.
    Which one is better depends on your needs. I think that constructing and executing a PreparedStatement can be a bit less performant than just a Statement, if you're only executing the query one time. But I don't think that difference will normally be noticable in the context of a given application.
    Additionally, if you have to pass any dates or strings to the query, you'll want PreparedStatement's parameters, rather than trying to format and escape things in the query string.

  • What's the difference between flash storage and solid state drive in MacBook Pro?

    What's the difference between MacBook Pro with flash storage and MacBook Pro with solid state drive?

    A SSD is packaged like any other notebook drive. Flash storage uses a different design and layout that connects directly to the motherboard using PCIe. It is faster than a normal SSD.
    SSD vs HDD: What's the Difference? | PCMag.com
    what are the differences between solid state drive and flash storage ...

  • What are the differences between this two statements???

    1.select * from counter where eboxid = (select acctid from zsyy_ocecs.cm_subs_subscriber where servnumber = ?);
    2.select b.* from zsyy_ocecs.CM_SUBS_SUBSCRIBER a,COUNTER b where a.acctid = b.eboxid and a.servnumber = ?;
    what are the differences between the 2 sql statements??
    I WILL APPRECIATE FOR YOUR ANSWERS VERY MUCH, BECAUSE I WAS PUZZLED WHEN I SAW THE EXECUTION PLANS.THANKS AGAIN. MR SHI.
    the followings are their execute plans:
    Command> select * from counter where eboxid = (select acctid from zsyy_ocecs.cm_subs_subscriber where servnumber = ?);
    Query Optimizer Plan:
    STEP: 1
    LEVEL: 2
    OPERATION: TblLkTtreeScan
    TBLNAME: ZSYY_OCECS.CM_SUBS_SUBSCRIBER
    IXNAME: IDX_SERVNUM
    INDEXED CONDITION: CM_SUBS_SUBSCRIBER.SERVNUMBER = qmark_1
    NOT INDEXED: ROWNUM < 3
    STEP: 2
    LEVEL: 2
    OPERATION: RowLkTtreeScan
    TBLNAME: COUNTER
    IXNAME: IDX_COUNTER
    INDEXED CONDITION:
    COUNTER.EBOXID = CM_SUBS_SUBSCRIBER.ACCTID
    NOT INDEXED: <NULL>
    STEP: 3
    LEVEL: 1
    OPERATION: NestedLoop
    TBLNAME: <NULL>
    IXNAME: <NULL>
    INDEXED CONDITION: <NULL>
    NOT INDEXED: <NULL>
    Command> select b.* from zsyy_ocecs.CM_SUBS_SUBSCRIBER a,COUNTER b where a.acctid = b.eboxid and a.servnumber = ?;
    Query Optimizer Plan:
    STEP: 1
    LEVEL: 2
    OPERATION: TmpTtreeScan
    TBLNAME: ZSYY_OCECS.CM_SUBS_SUBSCRIBER
    IXNAME: <NULL>
    INDEXED CONDITION: <NULL>
    NOT INDEXED: A.SERVNUMBER = qmark_1
    STEP: 2
    LEVEL: 2
    OPERATION: TblLkTtreeScan
    TBLNAME: COUNTER
    IXNAME: IDX_COUNTER
    INDEXED CONDITION: B.EBOXID
    = A.ACCTIDNOT INDEXED: <NULL>
    STEP: 3
    LEVEL: 1
    OPERATION: MergeJoin
    TBLNAME: <NULL>
    IXNAME: <NULL>
    INDEXED CONDITION: A.ACCTID = B.EBOXID
    NOT INDEXED: <NULL>
    Edited by: user9533799 on 2008-9-3 上午1:28

    If zsyy_ocecs.cm_subs_subscriber table returns one row for each servnumber, both statements would return the same data. But if there was a servnumber value on two rows, the first statement will throw an error (you a comparing a value with a set of values). You can rewrite the first query to avoid this:
    select * from counter where eboxid in (select acctid from zsyy_ocecs.cm_subs_subscriber where servnumber = ?);
    Conceptually they are different and the execution plan can't be the same.

  • What is the difference between the two update statements

    Hi Everyone
    Along with the emp table in scott kindly insert the to ins statement into emp.
    Insert into EMP
    (EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO)
    Values
    (8000, 'JAMES', 'CLERK', 7698, sysdate,
    1000, 10, 30);
    Insert into EMP
    (EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO)
    Values
    (8001, 'JAMES', 'CLERK', 7698, sysdate,
    1000, 10, 30);
    Consider the below two update statements.
    1) update emp a
    set ename=(select loc
    from dept b
    where a.deptno=b.deptno)
    where exists(select loc
    from dept b
    where a.deptno=b.deptno)
    2) update emp a
    set ename=(select loc
    from dept b
    where a.deptno=b.deptno)
    What is the difference between the 1st and 2nd update statement? what is the use of exists clause in the first update statement ? Can u suggest in what case will the two update statements provide different results.
    Thanks in advance

    Second one updates all records in emp. If there is no record in dept then ename will be updated to null.
    The first one only updates records in emp where a record in dept exists. It does not matter whether loc is non-null in dept or not. In an EXISTS query it doesn't matter if you do SELECT *, SELECT LOC, SELECT 1, SELECT NULL - Oracle just checks for existence.
    So most often an update like the first one is meant to improve performance by only updating those emp records that are needed. Usually that is a good idea.
    For this very specific case where all employees do belong to a department, all records in emp will be updated anyway, so for this specific case it actually makes worse performance because it does work to make an unnecessary check.
    Normally the EXISTS query is good for performance, but always figure out if they are needed first ;-)

  • What is the difference between hidden field and view state??

    Both view state and hidden field are use to store page specific information then, what is the difference between both of them??

    The ViewState of a page is actually stored in a large hidden field and it contains information about the entire page whereas a single hidden field that you define yourself is used to store some single value that should not be displayed.
    Please refer to the following page for more information about ASP.NET View State:
    http://msdn.microsoft.com/en-us/library/ms972976.aspx
    But please post your ASP.NET and web related questions at
    http://forums.asp.net in the future.
    Also, please remember to mark any helpful posts as answer.

  • What's the differences between connectors the old ones and newest ones?

    i developed an application with tomcat jakarta 5.1-mysql-java servlets, and i had been using the mysql-connector-java-3.1.8-bin.jar connector a little old uh, my question is what is the differences between the last mencionated and this version mysql-connector-java-5.0.0-beta-bin.jar, you say "just the version", i mean, i know there are many changes in the new ones but i don't like the idea to change all my application, and i would like to know what changes i have to do for update and compiling with them. i.e. i always did it like this:
    import java.sql.*;
    public class MultiUsos {
    private final static String log = "x";
    private final static String pswd = "x";
    private final static String Bd = "x";
    private final static String URL = "jdbc:mysql://localhost:3306/"+Bd;
    private Connection con = null;
    private ResultSet rs = null;
    private Statement stmt = null;
    private Conexion conexion = null;
    public int insert(String query) throws SQLException {
    try {
    con = conexion.getConexion(URL,log,pswd);
    con.setAutoCommit(false);
    if(con != null) {
    stmt = con.createStatement();
    r = stmt.executeUpdate(query);
    stmt.close();
    else System.out.print("� No existe conexion !");
    catch(SQLException e) {
    System.out.print("Error MySQL: ");
    e.printStackTrace();
    r = 0;
    return r;
    con.commit();
    return r;
    public void liberaConexion() {
    try {
    stmt.close();
    con.commit();
    con.close();
    catch(Exception e) {
    and i looked this example in new connectors:
    PreparedStatement pstmt = connection.prepareStatement("insert into......
    and things like that, i don't know if there were the same method in the older versions but if this is exclusive new for connectors, i'm fried.
    i will apreciate all comments and help, and sorry about my not good english.
    thanks.

    and i looked this example in new connectors:
    PreparedStatement pstmt =
    connection.prepareStatement("insert into......
    and things like that, i don't know if there were the
    same method in the older versions but if this is
    exclusive new for connectors, i'm fried.I am not sure if I understood your problem correctly but as I understand, you are worried because of the examples of PreparedStatement. That is an object representing a precompiled SQL statement. It is a part of the JDBC API, the same as Statement. There are several situations where the use of PreparedStatement is better than the usual Statement but this does not make the Statement obsolete.
    I would suggest you to read the JDBC tutorial
    http://java.sun.com/docs/books/tutorial/jdbc/
    especially the section dealing with the use of PreparedStatement.
    http://java.sun.com/docs/books/tutorial/jdbc/basics/prepared.html
    In general, it is better if you go through the complete tutorial and understand the features which are provided in the JDBC API.
    Hope I was helpful.

  • What is the difference between "Invisible" (11g) and "virtual" index?

    Hi
    What is the difference between the "Invisible" index and "virtual" index?
    Thanks
    Balaji

    Indexes can be visible or invisible. An invisible index is maintained by DML operations and cannot be used by the optimizer. Actually takes space, but is not to be used as part of a potential access path.
    AFAIK, a virtual index is created by the tools used in SQL statement access path tuning to provide an alternative for the optimizer to test. It does not take any real space as it is a pure in memory definition.

  • What is the diffrence between sap events and application events

    Hi all,
    what is the diffrence between sap events and application events.Can any one tell me with examples.
    regards,

    Hi,
    Look at this,
    <b>System Events (Default)</b>
    The event is passed to the application server, but does not trigger the PAI. If you have registered an event handler method in your ABAP program for the event (using the SET HANDLER statement), this method is executed on the application server.
    Within the event handler method, you can use the static method SET_NEW_OK_CODE of the global class CL_GUI_CFW to set a function code and trigger the PAI event yourself. After the PAI has been processed, the PBO event of the next screen is triggered.
    The advantage of using this technique is that the event handler method is executed automatically and there are no conflicts with the automatic input checks associated with the screen. The disadvantage is that the contents of the screen fields are not transported to the program, which means that obsolete values could appear on the next screen. You can work around this by using the SET_NEW_OK_CODE method to trigger field transport and the PAI event after the event handler has finished.
    <b>Application Events</b>
    The event is passed to the application server, and triggers the PAI. The function code that you pass contains an internal identifier. You do not have to evaluate this in your ABAP program. Instead, if you want to handle the event, you must include a method call in a PAI dialog module for the static method DISPATCH of the global class CL_GUI_CFW. If you have defined an event handler method in your ABAP program for the event (using the SET HANDLER statement), the DISPATCH method calls it. After the event handler has been processed, control returns to the PAI event after the DISPATCH statement and PAI processing continues.
    The advantage of this is that you can specify yourself the point at which the event is handled, and the contents of the screen fields are transported to the application server beforehand. The disadvantage is that this kind of event handling can lead to conflicts with the automatic input checks on the screen, causing events to be lost.
    Hope u understood.
    Thanks&Regards,
    Ruthra.R

  • WHAT'S THE DIFFERENCE BETWEEN.....

    Hi friends,
    Please enlighten me ....
    What's the difference between using this.....
    1. Add User command functionality to ALVgrid report
    In order to add user command functionality to the ALV grid you need to perform the following steps:
                        1. Update 'REUSE_ALV_GRID_DISPLAY' FM call to include 'USER_COMMAND' FORM
                    2. Create 'USER_COMMAND' FORM
    call function 'REUSE_ALV_GRID_DISPLAY'
           exporting
                i_callback_program      = gd_repid
                i_callback_top_of_page   = 'TOP-OF-PAGE'
                I_callback_user_command = 'USER_COMMAND'   "see FORM
                is_layout               = gd_layout
                it_fieldcat             = fieldcatalog[]
                i_save                  = 'X'
           tables
                t_outtab                = it_ekko
           exceptions
                program_error           = 1
                others                  = 2.
          FORM USER_COMMAND                                          *
          --> R_UCOMM                                                *
          --> RS_SELFIELD                                            *
    FORM user_command USING r_ucomm LIKE sy-ucomm
                      rs_selfield TYPE slis_selfield.
    Check function code
      CASE r_ucomm.
        WHEN '&IC1'.
      Check field clicked on within ALVgrid report
        IF rs_selfield-fieldname = 'EBELN'.
        Read data table, using index of row user clicked on
          READ TABLE it_ekko INTO wa_ekko INDEX rs_selfield-tabindex.
        Set parameter ID for transaction screen field
          SET PARAMETER ID 'BES' FIELD wa_ekko-ebeln.
        Sxecute transaction ME23N, and skip initial data entry screen
          CALL TRANSACTION 'ME23N' AND SKIP FIRST SCREEN.
        ENDIF.
      ENDCASE.
    ENDFORM.
    and using this----
    2. Add User command functionality to ALVgrid report
    In order modify PF_STATUS of ALV grid report you need to perform the following steps:
         1. Update 'REUSE_ALV_GRID_DISPLAY' FM call to include:
                        i_callback_pf_status_set = 'SET_PF_STATUS' statement.
         2. Create 'SET_PF_STATUS' FORM
         3. Create pf_status (i.e. 'ZNEWSTATUS').
              - It is recommend that you copy standard status'STANDARD' from function group SALV
                and modify it accordingly. ALV standard function codes always start with '&'.
    call function 'REUSE_ALV_GRID_DISPLAY'
           exporting
                i_callback_program      = gd_repid
                i_callback_top_of_page   = 'TOP-OF-PAGE'
                i_callback_pf_status_set = 'SET_PF_STATUS'   "see FORM
                is_layout               = gd_layout
                it_fieldcat             = fieldcatalog[]
                i_save                  = 'X'
           tables
                t_outtab                = it_ekko
           exceptions
                program_error           = 1
                others                  = 2.
          FORM SET_PF_STATUS                                         *
    FORM set_pf_status USING rt_extab TYPE slis_t_extab.
      SET PF-STATUS 'ZNEWSTATUS'.
                      "Copy of 'STANDARD' pf_status from fgroup SALV
    ENDFORM.
    I have assumed the former is used  when I am selecting a field on the list
    and the later when I have  created a pf-status. I mean to say... I have slected a field and click on some button to get further information.
    Please remove my confusion.
    Thanking you alll in advance,
    Hari Kiran.

    From their Terms & Conditions page:
    Grade A - Working phone in as new/mint condition. Complete with original box and accessories as sold new.
    Grade B (and Discounted) - Working phone in good condition with slight cosmetic blemishes. Charger supplied. If the phone includes a music player/radio then it is supplied with headphones. If the phone has PDA functionality a sync cable and/or docking cradle is supplied. Missing original packaging.
    Grade C (and Budget) - Working phone in poor cosmetic condition. Original or 3rd party charger supplied but missing accessories and original packaging.
    Substitute iPod for phone and I think it makes sense...
    tt2

  • What's the difference between jsp and jsf?

    who can tell me what's the difference between jsp and jsf?
    I'm puzzled when I found some of the technology in jsp is so similar to the ones in jsp( javaserver page)

    Hi,
    Find the difference between JSP and JSF
    1. A developer has more control with JSP, but (should) get easier development with JSF
    2. Event handling is done differently in JSP (HTTP) and JSF (Java)
    3. The UI is designed differently (or should be at least) with JSP (markup) and JSF (components).
    4. The end product should also be defined differently - JSP page versus a JSF application.
    Is this the only thing that is need to make a decision for either or? Probably not. There are other pieces that need to be taken in account when deciding which technology to use - tools support, enough components, type of application etc.... At this point there are not enough JSF components (although there are some interesting projects underway - Ajaxfaces, Myfaces, ADF Faces, and WebChart 3d) and enterprise tools support is still limited to a few tools vendor. Looking at our ADF Faces components they are currently available as early access (not production) and demands for these components are stacking up, literally, outside my office doorstep. Although I would love to make them production - now! - it is not a viable solution since we are still checking features and fixing critical bugs.
    All this combined - not enough enterprise level components in production, lacking tools support etc... - leave customers in a vacuum where the decision is either to continue with JSP, since it is mature and has a wide developer base, or move forward with JSF not sure if the support, or the developers will be there. This is particularly sensitive to customers that need to get started now and be production by summer.
    If you are in this vacuum here are some key points promoting JSF:
    1. Fundamental unit is the Component
    2. Built in event and state management
    3. Component sets can be provided by any vendor
    4. Closer to ASP.Net or Swing development
    5. Choice of UI technology
    6. Scale up (rich clients)
    7. Scale down (mobile devices)
    8. Built into J2EE containers in J2EE 5.0 (tentative)

Maybe you are looking for

  • Using the "consolidate" function has deleted 50% of my music files

    Hi there, Any help appreciated: I stupidly thought that because I had music files in a couple of locations as well as itunes that using itunes to consolidate them would solve the problem. As the itunes help menu says for "consolidating your library":

  • Load image into Photo Album

    I'm new to Oracle. Can I load image into database by using Photo Album by no writing any code? And how? If not,how to load image into database?

  • Microsoft Project Server 2010 - Need a query/report to show everyone who did not submit timesheet last week

    I need to create a MSPS 2010 query/report to send out to my project managers that show them everyone who did not submit their timesheet for the previous week.  I would like to be able to filter it by project/client but would settle for just a list of

  • No Value in VPRS Condition type

    Dear Experts While preparing a sales order , i am getting zero value against the cond type VPRS.It was working fine until recently this problem has started coming.In the Conditions details , it shows Incative-Inactive via formula of incorrect. the ac

  • Custom fields in Shopping cart at item level

    Dear Experts, We have a requirement to create the fields in the shopping cart. Through customizing we have defined the fields and configured them. Now we could able to see the custom fields in the Shopping cart at item level. The values to custom fie