-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMain.java
50 lines (41 loc) · 1.74 KB
/
Main.java
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
46
47
48
49
50
import java.sql.*;
public class Main {
private static String type = "wheels"; // or tires
public static void main(String[] args) {
String sql_query = ( type.equals("wheels") ) ? getWheelQuery() : getTireQuery() ;
try (
Connection connection = DBConnection.getConnection();
Statement statement = connection.createStatement(
ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY
);
ResultSet resultSet = statement.executeQuery( sql_query );
){
Item.getItems( resultSet, type );
} catch (SQLException e) {
e.printStackTrace();
}
}
private static String getWheelQuery() {
return "SELECT " +
"wheels.id as id, " +
"wheels.item_number as item_number, " +
"brand.brand_name as brand, " +
"model.model_name as model, " +
"wheel_finish.finish as finish " +
"FROM wheels " +
"JOIN brand ON wheels.brand = brand.id " +
"JOIN model ON wheels.model = model.id " +
"JOIN wheel_finish ON wheels.full_finish = wheel_finish.id WHERE wheels.active = 1";
}
private static String getTireQuery() {
return "SELECT " +
"tires.id as id, " +
"tires.item_number as item_number, " +
"brand.brand_name as brand, " +
"model.model_name as model " +
"FROM tires " +
"JOIN brand ON tires.brand = brand.id " +
"JOIN model ON tires.model = model.id WHERE tires.active = 1";
}
}