<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                ~~~ package cn.itcast.datasource.jdbctemplate; /** * @author: hcf * @qq: 46914685 * @email: 46914685@qq.com */ import cn.itcast.datasource.utils.DruidUtils; import org.springframework.jdbc.core.JdbcTemplate; /** * JdbcTemplate入門 */ public class JdbcTemplateDemo1 { public static void main(String[] args) { //1.導入jar包 //2.創建JDBCTemplate對象 JdbcTemplate template = new JdbcTemplate(DruidUtils.getDataSource()); //3.調用方法 String sql="update account set balance=? where id=?"; int count = template.update(sql, 5000.98,6); System.out.println(count); } } ~~~ ***** ~~~ package cn.itcast.datasource.jdbctemplate; import cn.itcast.datasource.domain.Emp; import cn.itcast.datasource.utils.DruidUtils; import org.junit.Test; import org.springframework.jdbc.core.BeanPropertyRowMapper; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.RowMapper; import java.sql.Date; import java.sql.ResultSet; import java.sql.SQLException; import java.util.List; import java.util.Map; /** * @author: hcf * @qq: 46914685 * @email: 46914685@qq.com */ public class JdbcTemplateDemo2 { //Junit單元測試,可以讓方法獨立執行 //1.獲取JDBCTemplate對象 private JdbcTemplate template = new JdbcTemplate(DruidUtils.getDataSource()); /** * 1) 修改1號數據的salary為10000 */ @Test public void test1() { //2.定義sql // String sql = "update emp set salary=10000 where id=1"; String sql = "update emp set salary=? where id=?"; //3.執行sql // int count = template.update(sql); int count = template.update(sql, 10000, 1); System.out.println(count); } /** * 2) 添加一條記錄 */ @Test public void test2() { //2.定義sql String sql = "insert into emp(ename,dept_id) values(?,?)"; //3.執行sql int count = template.update(sql, "喬峰", 2); System.out.println(count); } /** * 3)刪除剛才添加的記錄 */ @Test public void test3() { String sql = "delete from emp where id=?"; int count = template.update(sql, 4); System.out.println(count); } /** * 4) 查詢id為1的記錄,將其封裝為Map集合 * 注意:這個方法查詢的結果集長度只能是1 */ @Test public void test4() { String sql = "select * from emp where id=?"; // String sql = "select * from emp where id=? or id=?"; Map<String, Object> map = template.queryForMap(sql, 1); // Map<String, Object> map = template.queryForMap(sql, 1,2);//出錯 System.out.println(map); System.out.println(map.get("id")); } /** * 5) 查詢所有記錄,將其封裝為List */ @Test public void test5() { String sql = "select * from emp"; List<Map<String, Object>> list = template.queryForList(sql); for (Map<String, Object> stringObjectMap : list) { System.out.println(stringObjectMap); } } /** * 6) 查詢所有記錄,將其封裝為Emp對象的List集合 * 自定義emp */ @Test public void test6_1() { String sql = "select * from emp"; List<Emp> list = template.query(sql, new RowMapper<Emp>() { @Override public Emp mapRow(ResultSet rs, int i) throws SQLException { Emp emp = new Emp(); int id = rs.getInt("id"); String ename = rs.getString("ename"); int job_id = rs.getInt("job_id"); int mgr = rs.getInt("mgr"); Date joindate = rs.getDate("joindate"); double salary = rs.getDouble("salary"); double bouns = rs.getDouble("bouns"); int dept_id = rs.getInt("dept_id"); emp.setId(id); emp.setEname(ename); emp.setJob_id(job_id); emp.setMgr(mgr); emp.setJoindate(joindate); emp.setSalary(salary); emp.setBounds(bouns); emp.setDept_id(dept_id); return emp; } }); for (Emp emp : list) { System.out.println(emp); } } /** * 6) 查詢所有記錄,將其封裝為Emp對象的List集合 * 使用系統emp */ @Test public void test6_2() { String sql = "select * from emp"; List<Emp> list = template.query(sql, new BeanPropertyRowMapper<Emp>(Emp.class)); for (Emp emp : list) { System.out.println(emp); } } /** * 7) 查詢總記錄數 */ @Test public void test7(){ String sql="select count(id) from emp"; Long total = template.queryForObject(sql, Long.class); System.out.println(total); } } ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看