You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

140 lines
3.8 KiB

package de.hs_fulda.ciip.projjpn;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class Games {
private String databaseURL = "jdbc:ucanaccess://GamesDB.accdb";
public boolean checkConnection() {
try {
Connection connection = DriverManager.getConnection(databaseURL);
connection.close();
return true;
} catch (SQLException e) {
return false;
}
}
public String checkConsoles() {
String result = "";
String query = "SELECT Game_Console FROM Games";
boolean ninSwitch = false;
boolean xbox = false;
boolean multiplat = false;
try {
Connection connection = DriverManager.getConnection(databaseURL);
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(query);
while (resultSet.next()) {
String gameConsole = resultSet.getString("Game_Console");
if (ninSwitch && gameConsole.equals("Nintendo Switch")) {
continue;
} else if (xbox && gameConsole.equals("Xbox")) {
continue;
} else if (multiplat && gameConsole.equals("Multiplatform")) {
continue;
}
switch (gameConsole) {
case "Nintendo Switch":
ninSwitch = true;
break;
case "Xbox":
xbox = true;
break;
case "Multiplatform":
multiplat = true;
break;
}
result += gameConsole + ", ";
}
statement.close();
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
// The substring removes the last New line in the String.
return result.substring(0, result.length() - 2);
}
public String checkAllSamePublishers() {
String result = "";
String query = "SELECT Game_Name, Game_Publisher_EU, Game_Publisher_JP, Game_Publisher_NA FROM Games";
try {
Connection connection = DriverManager.getConnection(databaseURL);
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(query);
while (resultSet.next()) {
String gameName = resultSet.getString("Game_Name");
String gamePublisherEu = resultSet.getString("Game_Publisher_EU");
String gamePublisherJp = resultSet.getString("Game_Publisher_JP");
String gamePublisherNa = resultSet.getString("Game_Publisher_NA");
if (gamePublisherEu.equals(gamePublisherJp) && gamePublisherJp.equals(gamePublisherNa) && gamePublisherEu.equals(gamePublisherNa)) {
result += gameName + ", ";
}
}
statement.close();
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
// The substring removes the last New line in the String.
return result.substring(0, result.length() - 2);
}
public String checkAllDifferentPublishers() {
String result = "";
String query = "SELECT Game_Name, Game_Publisher_EU, Game_Publisher_JP, Game_Publisher_NA FROM Games";
try {
Connection connection = DriverManager.getConnection(databaseURL);
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(query);
while (resultSet.next()) {
String gameName = resultSet.getString("Game_Name");
String gamePublisherEu = resultSet.getString("Game_Publisher_EU");
String gamePublisherJp = resultSet.getString("Game_Publisher_JP");
String gamePublisherNa = resultSet.getString("Game_Publisher_NA");
if (!gamePublisherEu.equals(gamePublisherJp) && !gamePublisherJp.equals(gamePublisherNa) && !gamePublisherEu.equals(gamePublisherNa)) {
result += gameName + ", ";
}
}
statement.close();
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
// The substring removes the last New line in the String.
return result.substring(0, result.length() - 2);
}
}