package JDBCTemplate;

import Utils.JDBCUtils;
import org.junit.Test;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.List;
import java.util.Map;

public class JDBCTemplateDemo2 {
private JdbcTemplate template =new JdbcTemplate(JDBCUtils.getDataSource());
@Test
public void Test1(){

String sql="update account set balance =800 where id=1";
int count = template.update(sql);
System.out.println(count);
}
@Test
public void Test2(){
String sql="insert into account values(null,'ding',1000)";
int count = template.update(sql);
System.out.println(count);
}
@Test
public void Test3(){
String sql="delete from account where id=5";
int account = template.update(sql);
System.out.println(account);
}
@Test
public void Test4(){
String sql="select *from account where id=1";
Map<String, Object> map = template.queryForMap(sql);
System.out.println(map);
}
@Test
public void Test5(){
String sql="select *from account where id=? or id=?";
List<Map<String, Object>> list= template.queryForList(sql, 1, 2);
System.out.println(list);
}
@Test
public void Test6(){
String sql="select *from account";
List<account> list = template.query(sql, new BeanPropertyRowMapper<account>(account.class));
for (account account : list) {
System.out.println(list);
}
}
@Test
public void Test7(){
String sql="select count(id) from account";
Long along = template.queryForObject(sql, long.class);
System.out.println(along);
}
}
posted on 2022-01-25 19:57  凛至  阅读(41)  评论(0)    收藏  举报