· 6 years ago · Aug 06, 2019, 11:02 PM
1package com.java.aula2;
2
3import com.java.aula2.connection.ConnectionSQLite;
4
5import java.sql.PreparedStatement;
6import java.sql.SQLException;
7
8public class sqliteDDL {
9
10 private ConnectionSQLite connectionSQLite;
11
12 public sqliteDDL(ConnectionSQLite p) {
13 this.connectionSQLite = p;
14 }
15
16 public void createTableAddress() {
17
18 String sql = "";
19
20 this.executeSQLite(sql);
21 System.out.println("Criado tabela: tb_address");
22
23 }
24
25 public void createTableContact() {
26
27 String sql = "CREATE TABLE IF NOT EXISTS tb_contact(" +
28 "'id' INTEGER PRIMARY KEY autoincrement NOT NULL," +
29 "'name' TEXT NOT NULL," +
30 "'address' TEXT," +
31 "'phone' TEXT" +
32 ")";
33
34 this.executeSQLite(sql);
35 System.out.println("Criado tabela: tb_contact");
36
37 }
38
39 public void executeSQLite(String sql) {
40
41 try {
42
43 this.connectionSQLite.connect();
44
45 PreparedStatement pstmt = this.connectionSQLite.pstmt(sql);
46 pstmt.execute();
47
48 } catch (SQLException e) {
49 e.printStackTrace();
50 } finally {
51 this.connectionSQLite.disconnect();
52 }
53
54 }
55}