package demo;
import java.util.List;
import java.util.Map;
import javax.swing.text.html.HTMLDocument.Iterator;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import util.JDBCUtils;
import util.student;
public class JDBCDemo1 {
public static void main(String[] args) {
JdbcTemplate template=new JdbcTemplate(JDBCUtils.getDataSource());
//修改一条数据
int count=template.update("update score set chinese=60 where id=?",1);
System.out.println(count+"修改数据成功");
//添加一条记录
count =count +template.update("insert into score values(5,'pinky',88,98,76)");
System.out.println(count+"添加数据成功");
//删除上一步添加的记录
count =count +template.update("delete from score where id=?",5);
System.out.println(count+"删除数据成功");
//查询id为1的记录,将其封装为Map集合
Map map1=template.queryForMap("select * from score where id =1");
System.out.println(map1);
//查询所有记录,将其封装为List
List<Map<String, Object>> list1 = template.queryForList(
JDBCTemplate的执行语句(增删改查)
最新推荐文章于 2025-06-24 12:27:00 发布