Announcement Announcement Module
Collapse
No announcement yet.
jdbcTemplate or MappingSqlQuery Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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

  • #2
    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

    Comment

    Working...
    X