Created
September 14, 2016 12:53
-
-
Save ntakouris/e75181acdf417571f4f21d9c83bf6c4b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//load commodities | |
Main.log.info("Loading commodities..."); | |
String loadCommodities = "SELECT * FROM `commodities` ORDER BY `id` DESC LIMIT 1"; | |
Main.log.info("QUERY> " + loadCommodities); | |
Statement lcs = null; | |
ResultSet lcrs = null; | |
try{ | |
lcs = Database.createStatement(); | |
lcrs = lcs.executeQuery(loadCommodities); | |
if(lcrs.next()){ | |
int ironPrice = lcrs.getInt("iron"); | |
int goldPrice = lcrs.getInt("gold"); | |
int diamondPrice = lcrs.getInt("diamond"); | |
stockhouse.ironPrice = ironPrice; | |
stockhouse.goldPrice = goldPrice; | |
stockhouse.diamondPrice = diamondPrice; | |
Main.log.info("Iron price: " + ironPrice); | |
Main.log.info("Gold price: " + goldPrice); | |
Main.log.info("Diamond price: " + diamondPrice); | |
if(ironPrice <= 0){ | |
stockhouse.ironPrice = 0.3; | |
} | |
if(goldPrice <= 0){ | |
stockhouse.goldPrice = 8; | |
} | |
if(diamondPrice <= 0){ | |
stockhouse.diamondPrice = 30; | |
} | |
Main.log.info("Commodities loaded"); | |
}else{ | |
Main.log.warning("Commodities failed to load, going back to default prices"); | |
} | |
}catch(Exception e){ | |
e.printStackTrace(); | |
Main.log.warning("Commodities failed to load, going back to default prices"); | |
}finally{ | |
if(lcs!=null){ | |
try { | |
lcs.close(); | |
} catch (SQLException e) { | |
e.printStackTrace(); | |
} | |
}else if(lcrs!=null){ | |
try { | |
lcrs.close(); | |
} catch (SQLException e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment