· 5 years ago · Mar 24, 2020, 07:20 AM
1package com.emmanuel;
2
3import java.sql.Connection;
4import java.sql.DriverManager;
5import java.sql.SQLException;
6import java.sql.Statement;
7
8public class CreateTable {
9 public static void createNewTable() {
10 // SQLite connection string
11 String url = "jdbc:sqlite:sqlite/TodoList.db";
12
13 // SQL statement for creating a new table
14 String sql = "CREATE TABLE IF NOT EXISTS todos (\n"
15 + " id integer PRIMARY KEY,\n"
16 + " title text NOT NULL,\n"
17 + " description text NOT NULL,\n"
18 + " date text NOT NULL,\n"
19 + " isDone integer\n"
20 + ");";
21
22 try{
23 Connection conn = DriverManager.getConnection(url);
24 Statement stmt = conn.createStatement();
25 stmt.execute(sql);
26 } catch (SQLException e) {
27 System.out.println(e.getMessage());
28 }
29 }
30}