Update operations for Simplejdbctemplate in spring

Source: Internet
Author: User

Simplejdbctemplate Update operations

String Insertsql= "INSERT into users values (2, 'Lisi', 2)";

        // insert a row of records into the table, Row indicates the number of rows affected

int row=stj.update (insertsql);

System.out.println (row);//1

support for variable parameter update tables

String insertsql="insert into users values (?,?,?)";

Integerid=integer. valueOf (5);

String name="Xiaoqi";

Integerage=integer. valueOf (5);

int row= stj.update (Insertsql, id,name,age);

System. out. println (row); //1

String insertsql="Insertinto Users Values (: id,:name,:age)";

map<string,object> Map=newhashmap<string,object> ();

map. Put ("id", Integer. ) ValueOf(8));

map. Put ("name","Huangba");

map. Put ("age", Integer. ) ValueOf(8));

int row=stj.update (insertsql,map);

System. out. println (row);

Support for multi-line update operations

String insertsql2="Insertinto users Values (?,?,?)";

Integer Id=integer. valueOf (12);

String name="yaoling";

Integer Age=integer. valueOf (12);

Object[] Object1={id,name,age};

Integer Id2=integer. valueOf (11);

String name2="Jiujiu";

Integer Age2=integer. valueOf (11);

Object[] Object2={id2,name2,age2};

list<object[]> list=Newarraylist<object[]> ();

List.add (Object1);

List.add (OBJECT2);

Returns the number of rows that correspond to the effect

int [] row2=stj.batchupdate (INSERTSQL2, list);

Update operations for Simplejdbctemplate in spring

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.