Results 1 to 2 of 2

Thread: jdbcTemplate or MappingSqlQuery

  1. #1

    Exclamation jdbcTemplate or MappingSqlQuery

    Hi,
    I am doing small app.Up to now just for getting data frm database i used MappingSqlQuery.
    I want insert data into database. Whether i should use jdbctemplate or MappingSqlQuery.
    I dont know how to do that.

    By using MappingSqlQuery Can any one provide a sample code for that.
    Thanks in advance
    Regards,
    Sasikanth

  2. #2
    Join Date
    Jul 2005
    Posts
    5

    Smile

    Sasikanth, as the name of the class MappingSqlQuery suggests its used for
    queries or select statements.
    You need to use jdbcTemplate for doing updates(insert/update/delete).
    Here is a template:
    1) define the sql: "insert into <tableName> values(?, ? ...)"

    public int insert(<ObjectType> obj) {
    // set the param values defined in the sql statement above
    Object[] params = new Object[] {
    obj.getAttribute1(),
    obj.getAttribute2(),
    ...

    };

    int id = getJdbcTemplate().update(<insert sql>, params);
    return id ;
    }
    Hope this helps
    Imad Alsous

Posting Permissions

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