My code is wrong somehow :/
public static Connection con = null;
public static void createConnection()
{
try
{
Class.forName("com.mysql.jdbc.Driver").newInstance();
String str1 = "s1.infinitysrv.com:3306";
String str2 = "sagesca1_hiscores";
String str3 = "sagesca1_server";
String str4 = "pass";
con = DriverManager.getConnection("jdbc:mysql://" + str1 + "/" + str2, str3, str4);
stmt = con.createStatement();
System.out.println("Connection to SQL database successful!");
} catch (Exception localException) {
System.out.println("Connection to SQL database failed");
localException.printStackTrace();
}
}
public static Map<String, Clan> clans;
public static boolean sendClans(){
try {
try {
clans = (HashMap<String, Clan>) XStreamUtil.getXStream().fromXML(new FileInputStream("data/clans.xml"));
} catch (Exception e) {
clans = new HashMap<String, Clan>();
}
for (Map.Entry<String, Clan> entries : clans.entrySet()) {
final Clan clan = entries.getValue();
clan.setTransient();
PreparedStatement ps = con.prepareStatement("INSERT INTO clans(name,roomOwner) values (?, ?)");
ps.setString(1, clan.getName());
ps.setString(2, clan.getOwner());
ps.executeUpdate();
}
} catch (SQLException e) {
//e.printStackTrace();
return false;
}
return true;
}
Here's my ClanManager that calls the method sendClan
private Map<String, Clan> clans;
@SuppressWarnings("unchecked")
public ClanManager() {
Logger.getInstance().info("Loading clans....");
try {
clans = (HashMap<String, Clan>) XStreamUtil.getXStream().fromXML(new FileInputStream("data/clans.xml"));
} catch (Exception e) {
clans = new HashMap<String, Clan>();
}
for (Map.Entry<String, Clan> entries : clans.entrySet()) {
final Clan clan = entries.getValue();
clan.setTransient();
//Hiscores.sendClans();
}
Logger.getInstance().info("Loaded " +clans.size()+ " SageScape clans.");
}
I'm not quite sure what the problem is but the error points to this when I run my server:
PreparedStatement ps = con.prepareStatement("INSERT INTO clans(name,roomOwner) values (?, ?)");
I don't know what's wrong with the code, if anyone could help me I would love you forever.
Mapthat you have? (i.e. what doesownerandnamemap to with respect to theclansMapthat you have)Clanclass is populated with this info? And you've appropriategetter/settermethods to access these values?Clanclass?