-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathExecuteTest.java
More file actions
76 lines (61 loc) · 2.61 KB
/
ExecuteTest.java
File metadata and controls
76 lines (61 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package com.sqltest.db;
import com.sqltest.base.BaseTest;
import com.sqltest.dto.UserInfoDto;
import com.sqltest.model.UserInfo;
import io.github.cotide.dapper.Database;
import io.github.cotide.dapper.query.Sql;
import org.junit.Test;
import java.util.Date;
public class ExecuteTest extends BaseTest {
@Test
public void execute(){
try(Database db = getDatabase()){
db.beginTransaction();
final String insertSql =
"INSERT INTO user_info (user_Name,password,login,create_time) VALUES (?,?,?,?)";
int id = db.getSqlRun().execute(
insertSql,
"Execute Test",
"123456",
10086,
new Date()).asInt();
System.out.println("Object is :"+id);
assert (id>0):"insert is error";
final String updateSql =
"UPDATE user_info set user_Name = ? WHERE user_id = ?";
db.getSqlRun().execute(updateSql,"Execute Test2",id);
db.commit();
Sql sql = Sql.builder()
.select("user_id as id, user_Name as name")
.from(UserInfo.class).where("user_id = ?", id);
UserInfoDto resultDto = db.getSqlQuery().getDto(UserInfoDto.class,sql);
assert (resultDto!=null&&resultDto.getName().equals("Execute Test2")):"update get is error";
System.out.println(">>>>>>>>>> Result <<<<<<<<<<");
System.out.println(resultDto.getId());
System.out.println(resultDto.getName());
}
}
@Test
public void execute2(){
try(Database db = getDatabase()){
db.beginTransaction();
// Sql sql = Sql.builder().append(
// "INSERT INTO user_info (user_Name,password,login,create_time) VALUES (?,?,?,?);",
// "Execute Test1",
// "123456",
// 10086,
// new Date());
// sql.append("INSERT INTO user_info (user_Name,password,login,create_time) VALUES (?,?,?,?);",
// "Execute Test2",
// "123456",
// 10086,
// new Date());
String sql =
"INSERT INTO user_info (user_Name,password,login,create_time) VALUES ('ATest1','123456',10086,'2018-10-11 10:20:01');";
sql = sql+ "INSERT INTO user_info (user_Name,password,login,create_time) VALUES ('ATest1','123456',10086,'2018-10-11 10:20:01');";
System.out.println(sql);
db.getSqlRun().execute(sql);
db.commit();
}
}
}