Skip to content

Commit c92f84a

Browse files
author
wangyibing
committed
commit my homework for week 7
1 parent f867bab commit c92f84a

5 files changed

Lines changed: 49 additions & 30 deletions

File tree

04spring/jdbc/src/main/java/com/github/yibing/jdbc/DBUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class DBUtils {
99
private static final String driver = "com.mysql.jdbc.Driver";
1010
private static final String url = "jdbc:mysql://localhost:3306/student?&serverTimezone=Asia/Shanghai";
1111
private static final String username = "root";
12-
private static final String password = "123456";
12+
private static final String password = "";
1313
private static Connection connection = null;
1414

1515
public static Connection getConnection() {

04spring/jdbc/src/main/java/com/github/yibing/jdbc/JdbcDemo.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public void updateOne() {
9696
@Test
9797
public void batchInsert() {
9898
ArrayList<Student> list = new ArrayList<>();
99-
for (int i = 0; i < 10; i++) {
99+
for (int i = 0; i < 100000; i++) {
100100
list.add(new Student("student" + i));
101101
}
102102
// 使用 JDBC
@@ -109,11 +109,7 @@ public void batchInsert() {
109109
psmt = connection.prepareStatement(sql);
110110
connection.setAutoCommit(false);
111111
for (int i = 0; i < list.size(); i++) {
112-
if (i == 5) {
113-
psmt.setString(1, "sssssssssssssssssssssssssssssssssssssssssssssssssssssss");
114-
} else {
115-
psmt.setString(1, list.get(i).getName());
116-
}
112+
psmt.setString(1, list.get(i).getName());
117113
psmt.executeUpdate();
118114
}
119115
connection.commit();

05data/data-demo2/pom.xml

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,23 @@
4141
<artifactId>spring-boot-starter-test</artifactId>
4242
<scope>test</scope>
4343
</dependency>
44-
<!-- for spring boot -->
45-
<dependency>
46-
<groupId>org.apache.shardingsphere</groupId>
47-
<artifactId>sharding-jdbc-spring-boot-starter</artifactId>
48-
<version>${sharding-sphere.version}</version>
49-
</dependency>
44+
<!-- &lt;!&ndash; for spring boot &ndash;&gt;-->
45+
<!-- <dependency>-->
46+
<!-- <groupId>org.apache.shardingsphere</groupId>-->
47+
<!-- <artifactId>sharding-jdbc-spring-boot-starter</artifactId>-->
48+
<!-- <version>${sharding-sphere.version}</version>-->
49+
<!-- </dependency>-->
5050

51-
<!-- for spring namespace -->
51+
<!-- &lt;!&ndash; for spring namespace &ndash;&gt;-->
52+
<!-- <dependency>-->
53+
<!-- <groupId>org.apache.shardingsphere</groupId>-->
54+
<!-- <artifactId>sharding-jdbc-spring-namespace</artifactId>-->
55+
<!-- <version>${sharding-sphere.version}</version>-->
56+
<!-- </dependency>-->
5257
<dependency>
5358
<groupId>org.apache.shardingsphere</groupId>
54-
<artifactId>sharding-jdbc-spring-namespace</artifactId>
55-
<version>${sharding-sphere.version}</version>
59+
<artifactId>shardingsphere-jdbc-core-spring-boot-starter</artifactId>
60+
<version>5.0.0-alpha</version>
5661
</dependency>
5762
<dependency>
5863
<groupId>org.springframework.boot</groupId>

05data/data-demo2/src/main/resources/application.yml

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,33 @@
11
spring:
22
shardingsphere:
33
datasource:
4-
names: master,slave1
5-
master:
6-
driver-class-name: com.mysql.jdbc.Driver
4+
common:
75
type: com.zaxxer.hikari.HikariDataSource
8-
jdbcUrl: jdbc:mysql://localhost:3311/mall?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai
6+
driver-class-name: com.mysql.jdbc.Driver
97
username: root
8+
names: master,slave1,slave2
9+
master:
10+
jdbcUrl: jdbc:mysql://localhost:3306/mall?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai
1011
slave1:
11-
driver-class-name: com.mysql.jdbc.Driver
12-
type: com.zaxxer.hikari.HikariDataSource
1312
jdbcUrl: jdbc:mysql://localhost:3316/mall?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai
14-
username: root
15-
masterslave:
16-
master-data-source-name: master
17-
slave-data-source-names: slave1
18-
load-balance-algorithm-type: random
13+
slave2:
14+
jdbcUrl: jdbc:mysql://localhost:3317/mall?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai
1915
props:
2016
sql:
2117
show: true
2218
enabled: true
19+
rules:
20+
replica-query:
21+
load-balancers:
22+
round-robin:
23+
type: ROUND_ROBIN
24+
props:
25+
workid: 123
26+
datasources:
27+
ps_ds:
28+
primary-data-source-name: master
29+
replica-data-source-names: slave1,slave2
30+
load-balancer-name: round_robin
2331
jackson:
2432
time-zone: GMT+8
2533
date-format: yyyy-MM-dd HH:mm:ss
@@ -31,7 +39,7 @@ mybatis:
3139
type-aliases-package: com.github.yibing.data.datademo2.entity
3240
mapper-locations: classpath:dao/*.xml
3341
server:
34-
port: 8088
42+
port: 8086
3543
logging:
3644
level:
3745
com.github.yibing.data.datademo2: debug

05data/data-demo2/src/main/resources/dao/ProcuctMapper.xml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
22
<mapper namespace="com.github.yibing.data.datademo2.dao.ProductMapper">
33

4-
<select id="listProducts" resultType="com.github.yibing.data.datademo2.entity.Product">
5-
select * from product
4+
<resultMap id="baseResult" type="com.github.yibing.data.datademo2.entity.Product">
5+
<id column="product_id" jdbcType="VARCHAR" property="productId"/>
6+
<result column="price" jdbcType="DECIMAL" property="price"/>
7+
<result column="product_name" jdbcType="VARCHAR" property="productName"/>
8+
<result column="create_time" jdbcType="DATE" property="createTime"/>
9+
<result column="update_time" jdbcType="DATE" property="updateTime"/>
10+
<result column="description" jdbcType="VARCHAR" property="description"/>
11+
<result column="product_type" jdbcType="VARCHAR" property="productType"/>
12+
<result column="status" jdbcType="INTEGER" property="status"/>
13+
</resultMap>
14+
<select id="listProducts" resultMap="baseResult">
15+
select product_id,price,product_name,create_time,update_time,description,product_type,status from product
616
</select>
717

818
<insert id="insert" parameterType="com.github.yibing.data.datademo2.entity.Product">

0 commit comments

Comments
 (0)