-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathMainApplication.java
More file actions
44 lines (38 loc) · 1.58 KB
/
MainApplication.java
File metadata and controls
44 lines (38 loc) · 1.58 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
import com.mysql.cj.jdbc.Driver;
import daos.Engine;
import daos.PhoneRepository;
import models.Phone;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.StringJoiner;
/**
* @author git-leon
* @version 1.0.0
* @date 8/2/21 9:49 AM
*/
public class MainApplication {
public static void main(String[] args) {
Engine engine = new Engine();
engine.registerJDBCDriver();
Connection mysqlDbConnection = engine.getConnection("mysql");
PhoneRepository phoneRepository = new PhoneRepository(mysqlDbConnection);
engine.executeStatement(mysqlDbConnection, "DROP DATABASE IF EXISTS walmart;");
engine.executeStatement(mysqlDbConnection, "CREATE DATABASE IF NOT EXISTS walmart;");
engine.executeStatement(mysqlDbConnection, "USE walmart;");
engine.executeStatement(mysqlDbConnection, new StringBuilder()
.append("CREATE TABLE IF NOT EXISTS walmart.phone(")
.append("id int auto_increment primary key,")
.append("name text not null,")
.append("color varchar(30) not null,")
.append("carrier varchar(30),")
.append("cameras int,")
.append("price int not null);")
.toString());
phoneRepository.create(new Phone(20, "ePhone", "'blue'", "'sprint'",3, 425.0));
phoneRepository.create(new Phone(21, "strawberry", "'red'", "'tmobile'", 3, 599.0));
System.out.println(phoneRepository.readAll());
}
}