· 5 years ago · Jun 18, 2020, 03:46 PM
1public class Main {
2
3 /**
4 * Create a new table in the test database
5 *
6 */
7 public static void createNewTable() {
8 // SQLite connection string
9 String url = "jdbc:sqlite:C://sqlite/db/tests.db";
10
11 // SQL statement for creating a new table
12 String sql = "CREATE TABLE IF NOT EXISTS warehouses (\n"
13 + " id integer PRIMARY KEY,\n"
14 + " name text NOT NULL,\n"
15 + " capacity real\n"
16 + ");";
17
18 try (Connection conn = DriverManager.getConnection(url);
19 Statement stmt = conn.createStatement()) {
20 // create a new table
21 stmt.execute(sql);
22 } catch (SQLException e) {
23 System.out.println(e.getMessage());
24 }
25 }
26
27 /**
28 * @param args the command line arguments
29 */
30 public static void main(String[] args) {
31 createNewTable();
32 }
33
34}