-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
45 lines (41 loc) · 1.56 KB
/
Copy pathMain.java
File metadata and controls
45 lines (41 loc) · 1.56 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
import Classes.Menu;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.SQLException;
public class Main {
private static final String DATABASE = "Database.db";
public static Connection conn = null;
public static Connection initializeDatabase(String path) {
String url = "jdbc:sqlite:" + path;
Connection connection = null;
try {
connection = DriverManager.getConnection(url);
if (connection != null) {
DatabaseMetaData metaData = connection.getMetaData();
System.out.println("Using driver: " + metaData.getDriverName());
System.out.println("Database connected successfully.");
} else {
System.out.println("Null Connection");
}
} catch (SQLException e) {
System.out.println(e.getMessage());
System.out.println("There was a problem connecting to the database.");
}
return connection;
}
public static void main(String[] args) {
conn = initializeDatabase(DATABASE);
Menu menu = new Menu(conn); // Instantiate the application
while (true) {
int choice = menu.getNextOption(); // Get the option wanted from the customer
if (choice == 15) { // Exit loop
System.out.println("Exiting program");
break;
} else {
// Run the menu option for the selected choice
menu.runMenuOption(choice);
}
}
}
}