From 602a4d1098f13b9c1a10337e5d4ab6ae7546caa2 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Thu, 5 Dec 2019 11:03:24 +0100 Subject: [PATCH] Removing SQLException --- .../src/de/steamwar/sql/Schematic.java | 96 +++++++++++-------- 1 file changed, 54 insertions(+), 42 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/sql/Schematic.java b/SpigotCore_Main/src/de/steamwar/sql/Schematic.java index bf00fc2..fa876c6 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/Schematic.java +++ b/SpigotCore_Main/src/de/steamwar/sql/Schematic.java @@ -147,69 +147,81 @@ public class Schematic { updateDB(); } - public Clipboard load() throws WrongVersionException, SQLException, IOException, NoClipboardException { + public Clipboard load() throws WrongVersionException, IOException, NoClipboardException { if(Core.getVersion() <= 12 && schemFormat) throw new WrongVersionException(); ResultSet rs = SQL.select("SELECT SchemData FROM Schematic WHERE SchemID = " + schemID); - rs.next(); - InputStream is = rs.getBlob("SchemData").getBinaryStream(); - switch(Core.getVersion()){ - case 8: - return Schematic_8.getClipboard(is); - case 14: - return Schematic_14.getClipboard(is, schemFormat); - default: - return Schematic_12.getClipboard(is); + try { + rs.next(); + InputStream is = rs.getBlob("SchemData").getBinaryStream(); + switch(Core.getVersion()){ + case 8: + return Schematic_8.getClipboard(is); + case 14: + return Schematic_14.getClipboard(is, schemFormat); + default: + return Schematic_12.getClipboard(is); + } + } catch (SQLException e) { + throw new IOException(e); } } - public void loadToPlayer(Player player) throws SQLException, IOException, NoClipboardException, WrongVersionException { + public void loadToPlayer(Player player) throws IOException, NoClipboardException, WrongVersionException { if(Core.getVersion() <= 12 && schemFormat) throw new WrongVersionException(); ResultSet rs = SQL.select("SELECT SchemData FROM Schematic WHERE SchemID = " + schemID); - rs.next(); - InputStream is = rs.getBlob("SchemData").getBinaryStream(); - switch(Core.getVersion()){ - case 8: - Schematic_8.setPlayerClipboard(player, is); - break; - case 14: - Schematic_14.setPlayerClipboard(player, is, schemFormat); - break; - default: - Schematic_12.setPlayerClipboard(player, is); + try { + rs.next(); + InputStream is = rs.getBlob("SchemData").getBinaryStream(); + switch(Core.getVersion()){ + case 8: + Schematic_8.setPlayerClipboard(player, is); + break; + case 14: + Schematic_14.setPlayerClipboard(player, is, schemFormat); + break; + default: + Schematic_12.setPlayerClipboard(player, is); + } + } catch (SQLException e) { + throw new IOException(e); } } - public void saveOldFormatFromPlayer(Player player) throws SQLException, IOException, NoClipboardException { + public void saveOldFormatFromPlayer(Player player) throws IOException, NoClipboardException { saveFromPlayer(player, false); } - public void saveFromPlayer(Player player) throws SQLException, IOException, NoClipboardException { + public void saveFromPlayer(Player player) throws IOException, NoClipboardException { saveFromPlayer(player, true); } - private void saveFromPlayer(Player player, boolean newFormat) throws SQLException, IOException, NoClipboardException { - PreparedStatement st = SQL.getCon().prepareStatement("UPDATE Schematic SET SchemData = ?, SchemFormat = ? WHERE SchemID = " + schemID); - byte[] data; - switch(Core.getVersion()){ - case 8: - newFormat = false; - data = Schematic_8.getPlayerClipboard(player); - break; - case 14: - data = Schematic_14.getPlayerClipboard(player, newFormat); - break; - default: - newFormat = false; - data = Schematic_12.getPlayerClipboard(player); + private void saveFromPlayer(Player player, boolean newFormat) throws IOException, NoClipboardException { + try{ + PreparedStatement st = SQL.getCon().prepareStatement("UPDATE Schematic SET SchemData = ?, SchemFormat = ? WHERE SchemID = " + schemID); + byte[] data; + switch(Core.getVersion()){ + case 8: + newFormat = false; + data = Schematic_8.getPlayerClipboard(player); + break; + case 14: + data = Schematic_14.getPlayerClipboard(player, newFormat); + break; + default: + newFormat = false; + data = Schematic_12.getPlayerClipboard(player); + } + st.setBlob(1, new ByteArrayInputStream(data)); + st.setBoolean(2, newFormat); + st.executeUpdate(); + schemFormat = newFormat; + }catch(SQLException e){ + throw new IOException(e); } - st.setBlob(1, new ByteArrayInputStream(data)); - st.setBoolean(2, newFormat); - st.executeUpdate(); - schemFormat = newFormat; } public void remove(){