五月天青色头像情侣网名,国产亚洲av片在线观看18女人,黑人巨茎大战俄罗斯美女,扒下她的小内裤打屁股

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

添加

2023-04-07 18:50 作者:終極向晚葵  | 我要投稿

package com.itheima.example;

import com.alibaba.druid.pool.DruidDataSourceFactory;
import com.itheima.pojo.Brand;
import org.junit.Test;

import javax.sql.DataSource;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

/*
*
* 品牌數(shù)據(jù)的增刪改查操作
* ?*/
public class BrandTest {

/* ?* 1.查詢所有
? * 2.參數(shù);不需要
? * 3.結(jié)果;List<Brand>
? * */
? ?@Test
? ?public void testSelectAll() throws Exception {
? ? ? ?//1.獲取連接的Connection對象
? ? ? ?//3.加載配置文件
? ? ? ?Properties prop =new Properties();
? ? ? ?prop.load(new FileInputStream("src/druid.properties"));//注意去掉“jdbc_demo/”
? ? ? ?//4.獲取連接池對象
? ? ? ?DataSource dataSource = DruidDataSourceFactory.createDataSource(prop);
? ? ? ?//5.獲取數(shù)據(jù)庫連接
? ? ? ?Connection conn = dataSource.getConnection();
? ? ? ?//定義sql
? ? ? ?String sql = "select * from tb_brand";
? ? ? ?//獲取pstmt對象
? ? ? ?PreparedStatement pstmt = conn.prepareStatement(sql);
? ? ? ?//設(shè)置參數(shù)

? ? ? ?//執(zhí)行SQL
? ? ? ?ResultSet rs = pstmt.executeQuery();
? ? ? ?//處理結(jié)果List<brand>封裝Brand對象,裝載List集合
? ? ? ?Brand brand =null;
? ? ? ?List<Brand>brands = new ArrayList<>();
? ? ? ?while(rs.next()){
? ? ? ? ? ?//獲取數(shù)據(jù)
? ? ? ? ? ?int id = rs.getInt("id");//alt+enter
? ? ? ? ? ?String brandName = rs.getString("brand_name");
? ? ? ? ? ?String companyName = rs.getString("company_name");
? ? ? ? ? ?int ordered = rs.getInt("ordered");
? ? ? ? ? ?String description = rs.getString("description");
? ? ? ? ? ?int status = rs.getInt("status");
? ? ? ? ? ?//封裝brand對象
? ? ? ? ? ?brand= new Brand();
? ? ? ? ? ?brand.setId(id);
? ? ? ? ? ?brand.setBranName(brandName);
? ? ? ? ? ?brand.setOrdered(ordered);
? ? ? ? ? ?brand.getCompanyName(companyName);
? ? ? ? ? ?brand.setStatus(status);
? ? ? ? ? ?brand.setDescription(description);
? ? ? ? ? ?//裝載集合
? ? ? ? ? ?brands.add(brand);

? ? ? ?}
? ? ? ?System.out.println(brands);
? ? ? ?//7.釋放資源
? ? ? ?rs.close();
? ? ? ?pstmt.close();
? ? ? ?conn.close();
? ?}
? ?/*添加
? ?*1.sql:select * from tb-brand
? ?*2.參數(shù);不需要
? ?* 3.結(jié)果List<Brand>
? ?* */
? ?@Test
? ?public void testAdd() throws Exception {
? ? ? ?//1.獲取連接的Connection對象
? ? ? ?//3.加載配置文件
? ? ? ?String brandName ="香飄飄";
? ? ? ?String companyName ="香飄飄";
? ? ? ?int ordered =1;
? ? ? ?String description ="繞地球一圈";
? ? ? ?int status =1;

? ? ? ?Properties prop =new Properties();
? ? ? ?prop.load(new FileInputStream("src/druid.properties"));//注意去掉“jdbc_demo/”
? ? ? ?//4.獲取連接池對象
? ? ? ?DataSource dataSource = DruidDataSourceFactory.createDataSource(prop);
? ? ? ?//5.獲取數(shù)據(jù)庫連接
? ? ? ?Connection conn = dataSource.getConnection();
? ? ? ?//定義sql
? ? ? ?String sql = "insert into tb_brand(brand_name,company_name,ordered,description,status)values(?,?,?,?,?)";
? ? ? ?//獲取pstmt對象
? ? ? ?PreparedStatement pstmt = conn.prepareStatement(sql);
? ? ? ?//設(shè)置參數(shù)
? ? ? ?pstmt.setString(1,brandName);
? ? ? ?pstmt.setString(2,companyName);
? ? ? ?pstmt.setInt(3,ordered);
? ? ? ?pstmt.setString(4,description);
? ? ? ?pstmt.setInt(5,status);
? ? ? ?//執(zhí)行SQL
? ? ? ?int count = pstmt.executeUpdate();//影響行數(shù)
? ? ? ?//6.處理結(jié)果
? ? ? ?System.out.println(count>0);

? ? ? ?//7.釋放資源

? ? ? ?pstmt.close();
? ? ? ?conn.close();
? ?}
}

testSelectAll()運行結(jié)果
testAdd()運行結(jié)果


添加的評論 (共 條)

分享到微博請遵守國家法律
定陶县| 怀宁县| 广宁县| 潼南县| 西藏| 宁津县| 沁水县| 无为县| 平顶山市| 体育| 安达市| 清新县| 家居| 清河县| 安远县| 富蕴县| 延安市| 房产| 鄂伦春自治旗| 平阳县| 泌阳县| 宁蒗| 桃园县| 台湾省| 平原县| 泽库县| 安义县| 芦山县| 筠连县| 海伦市| 元阳县| 富锦市| 遵化市| 巴南区| 敖汉旗| 浑源县| 五峰| 醴陵市| 乌恰县| 宁波市| 洞头县|