-
Dec 15th, 2005, 11:10 PM
#1
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
-
Dec 16th, 2005, 06:58 AM
#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
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
-
Forum Rules