Skip to content
Snippets Groups Projects
Commit 89e98b6d authored by Schuh Martin's avatar Schuh Martin
Browse files

Update: OracleDB.java (cosmetic fixes)

Update. AzureDB.java (cosmetic fixes)
parent a39fc03c
No related branches found
No related tags found
4 merge requests!74V1,!73Initial commit,!71Merge DataBase into Development,!11Merge DataBase to development
...@@ -94,6 +94,33 @@ public class AzureDB implements ISQLDataBase { ...@@ -94,6 +94,33 @@ public class AzureDB implements ISQLDataBase {
} }
} }
@Override
public PlayerStatistics getStatistics(String playerName) throws SQLException {
try(Connection connection = connect()) {
String sql = "SELECT games_won, games_lost, kills, deaths, blocks_destroyed, ingame_time FROM players WHERE player_name = ?";
PreparedStatement stmt = connection.prepareStatement(sql);
stmt.setString(1, playerName);
log.info("Sending SQL statement.");
ResultSet rs = stmt.executeQuery();
if(rs.next() == false){ //if no data matches
throw new SQLException("No match on SQL database!");
}
PlayerStatistics stats = new PlayerStatistics(0, 0, 0, 0, 0, 0);
while(rs.next()) {
stats = new PlayerStatistics(rs.getInt("games_won"), rs.getInt("games_lost"), rs.getInt("kills"), rs.getInt("deaths"), rs.getInt("blocks_destroyed"), rs.getInt("ingame_time"));
}
rs.close();
stmt.close();
log.info("Player statistics retrieved successfully from SQL server!");
return stats;
}
catch(Exception e){
log.error(e);
throw new SQLException("Error retrieving player statistics from SQL server! " + e.getMessage());
}
}
@Override @Override
public MapData getCommunityMapByID(String mapID) throws SQLException { public MapData getCommunityMapByID(String mapID) throws SQLException {
try(Connection connection = connect()) { try(Connection connection = connect()) {
...@@ -129,6 +156,31 @@ public class AzureDB implements ISQLDataBase { ...@@ -129,6 +156,31 @@ public class AzureDB implements ISQLDataBase {
} }
} }
@Override
public String checkCredentials(String playerName) throws SQLException {
try(Connection connection = connect()) {
String sql = "SELECT player_pw FROM players WHERE player_name = ?";
PreparedStatement stmt = connection.prepareStatement(sql);
stmt.setString(1, playerName);
log.info("Sending SQL statement.");
ResultSet rs = stmt.executeQuery();
String password = "";
while(rs.next()) {
password = rs.getString("player_pw");
}
rs.close();
stmt.close();
log.info("Player credentials retrieved successfully from SQL server!");
return password;
}
catch(Exception e){
log.error(e);
throw new SQLException("Error retrieving retrieving player credentials from SQL server! " + e.getMessage());
}
}
@Override @Override
public void uploadCommunityMap(MapData map) throws SQLException { public void uploadCommunityMap(MapData map) throws SQLException {
try(Connection connection = connect()) { try(Connection connection = connect()) {
...@@ -172,58 +224,6 @@ public class AzureDB implements ISQLDataBase { ...@@ -172,58 +224,6 @@ public class AzureDB implements ISQLDataBase {
} }
} }
@Override
public String checkCredentials(String playerName) throws SQLException {
try(Connection connection = connect()) {
String sql = "SELECT player_pw FROM players WHERE player_name = ?";
PreparedStatement stmt = connection.prepareStatement(sql);
stmt.setString(1, playerName);
log.info("Sending SQL statement.");
ResultSet rs = stmt.executeQuery();
String password = "";
while(rs.next()) {
password = rs.getString("player_pw");
}
rs.close();
stmt.close();
log.info("Player credentials retrieved successfully from SQL server!");
return password;
}
catch(Exception e){
log.error(e);
throw new SQLException("Error retrieving retrieving player credentials from SQL server! " + e.getMessage());
}
}
@Override
public PlayerStatistics getStatistics(String playerName) throws SQLException {
try(Connection connection = connect()) {
String sql = "SELECT games_won, games_lost, kills, deaths, blocks_destroyed, ingame_time FROM players WHERE player_name = ?";
PreparedStatement stmt = connection.prepareStatement(sql);
stmt.setString(1, playerName);
log.info("Sending SQL statement.");
ResultSet rs = stmt.executeQuery();
if(rs.next() == false){ //if no data matches
throw new SQLException("No match on SQL database!");
}
PlayerStatistics stats = new PlayerStatistics(0, 0, 0, 0, 0, 0);
while(rs.next()) {
stats = new PlayerStatistics(rs.getInt("games_won"), rs.getInt("games_lost"), rs.getInt("kills"), rs.getInt("deaths"), rs.getInt("blocks_destroyed"), rs.getInt("ingame_time"));
}
rs.close();
stmt.close();
log.info("Player statistics retrieved successfully from SQL server!");
return stats;
}
catch(Exception e){
log.error(e);
throw new SQLException("Error retrieving player statistics from SQL server! " + e.getMessage());
}
}
@Override @Override
public void updatePlayerStats(PlayerStatistics stats, PlayerAccount account) throws SQLException { public void updatePlayerStats(PlayerStatistics stats, PlayerAccount account) throws SQLException {
try(Connection connection = connect()) { try(Connection connection = connect()) {
......
...@@ -95,6 +95,33 @@ public class OracleDB implements ISQLDataBase { ...@@ -95,6 +95,33 @@ public class OracleDB implements ISQLDataBase {
} }
} }
@Override
public PlayerStatistics getStatistics(String playerName) throws SQLException {
try(Connection connection = connect()) {
String sql = "SELECT games_won, games_lost, kills, deaths, blocks_destroyed, ingame_time FROM battlearenadata.players WHERE player_name = ?";
PreparedStatement stmt = connection.prepareStatement(sql);
stmt.setString(1, playerName);
log.info("Sending SQL statement.");
ResultSet rs = stmt.executeQuery();
if(rs.next() == false){ //if no data matches
throw new SQLException("No match on SQL database!");
}
PlayerStatistics stats = new PlayerStatistics(0, 0, 0, 0, 0, 0);
while(rs.next()) {
stats = new PlayerStatistics(rs.getInt("games_won"), rs.getInt("games_lost"), rs.getInt("kills"), rs.getInt("deaths"), rs.getInt("blocks_destroyed"), rs.getInt("ingame_time"));
}
rs.close();
stmt.close();
log.info("Player statistics retrieved successfully from SQL server!");
return stats;
}
catch(Exception e){
log.error(e);
throw new SQLException("Error retrieving player statistics from SQL server! " + e.getMessage());
}
}
@Override @Override
public MapData getCommunityMapByID(String mapID) throws SQLException { public MapData getCommunityMapByID(String mapID) throws SQLException {
try(Connection connection = connect()) { try(Connection connection = connect()) {
...@@ -130,6 +157,31 @@ public class OracleDB implements ISQLDataBase { ...@@ -130,6 +157,31 @@ public class OracleDB implements ISQLDataBase {
} }
} }
@Override
public String checkCredentials(String playerName) throws SQLException {
try(Connection connection = connect()) {
String sql = "SELECT player_pw FROM battlearenadata.players WHERE player_name = ?";
PreparedStatement stmt = connection.prepareStatement(sql);
stmt.setString(1, playerName);
log.info("Sending SQL statement.");
ResultSet rs = stmt.executeQuery();
String password = "";
while(rs.next()) {
password = rs.getString("player_pw");
}
rs.close();
stmt.close();
log.info("Player credentials retrieved successfully from SQL server!");
return password;
}
catch(Exception e){
log.error(e);
throw new SQLException("Error retrieving retrieving player credentials from SQL server! " + e.getMessage());
}
}
@Override @Override
public void uploadCommunityMap(MapData map) throws SQLException { public void uploadCommunityMap(MapData map) throws SQLException {
try(Connection connection = connect()) { try(Connection connection = connect()) {
...@@ -173,58 +225,6 @@ public class OracleDB implements ISQLDataBase { ...@@ -173,58 +225,6 @@ public class OracleDB implements ISQLDataBase {
} }
} }
@Override
public String checkCredentials(String playerName) throws SQLException {
try(Connection connection = connect()) {
String sql = "SELECT player_pw FROM battlearenadata.players WHERE player_name = ?";
PreparedStatement stmt = connection.prepareStatement(sql);
stmt.setString(1, playerName);
log.info("Sending SQL statement.");
ResultSet rs = stmt.executeQuery();
String password = "";
while(rs.next()) {
password = rs.getString("player_pw");
}
rs.close();
stmt.close();
log.info("Player credentials retrieved successfully from SQL server!");
return password;
}
catch(Exception e){
log.error(e);
throw new SQLException("Error retrieving retrieving player credentials from SQL server! " + e.getMessage());
}
}
@Override
public PlayerStatistics getStatistics(String playerName) throws SQLException {
try(Connection connection = connect()) {
String sql = "SELECT games_won, games_lost, kills, deaths, blocks_destroyed, ingame_time FROM battlearenadata.players WHERE player_name = ?";
PreparedStatement stmt = connection.prepareStatement(sql);
stmt.setString(1, playerName);
log.info("Sending SQL statement.");
ResultSet rs = stmt.executeQuery();
if(rs.next() == false){ //if no data matches
throw new SQLException("No match on SQL database!");
}
PlayerStatistics stats = new PlayerStatistics(0, 0, 0, 0, 0, 0);
while(rs.next()) {
stats = new PlayerStatistics(rs.getInt("games_won"), rs.getInt("games_lost"), rs.getInt("kills"), rs.getInt("deaths"), rs.getInt("blocks_destroyed"), rs.getInt("ingame_time"));
}
rs.close();
stmt.close();
log.info("Player statistics retrieved successfully from SQL server!");
return stats;
}
catch(Exception e){
log.error(e);
throw new SQLException("Error retrieving player statistics from SQL server! " + e.getMessage());
}
}
@Override @Override
public void updatePlayerStats(PlayerStatistics stats, PlayerAccount account) throws SQLException { public void updatePlayerStats(PlayerStatistics stats, PlayerAccount account) throws SQLException {
try(Connection connection = connect()) { try(Connection connection = connect()) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment