-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
43 lines (37 loc) · 1.3 KB
/
Copy pathMain.java
File metadata and controls
43 lines (37 loc) · 1.3 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
import parser.Parser;
import validator.QueryValidator;
import validator.ValidationException;
import executor.QueryExecutor;
import storage.Database;
import query.Query;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Database db = new Database();
db.loadData();
Parser parser = new Parser();
QueryValidator validator = new QueryValidator(db);
QueryExecutor executor = new QueryExecutor(db);
Scanner scanner = new Scanner(System.in);
System.out.println("Mini SQL Engine Started. Type 'exit' to quit.");
while (true) {
System.out.print("SQL> ");
String input = scanner.nextLine();
if (input.equalsIgnoreCase("exit")) {
break;
}
try {
Query query = parser.parse(input);
validator.validate(query);
query.accept(executor);
} catch (ValidationException e) {
System.out.println("Validation Error: " + e.getMessage());
} catch (Exception e) {
System.out.println("Error: " + e.getClass().getSimpleName());
e.printStackTrace();
}
}
scanner.close();
System.out.println("SQL Engine stopped.");
}
}