k, here is my code : https://github.com/stelar7/Warner/ there is an error on line 144-161, not sure where tho... I think a lot of my code is wrong, some help would be quite nice TL;DR: need help with using MySql in Java...
From what I see, I think the problem is that you're using a prepared statement like a normal query. Prepared statements require a few different steps than a normal query. First, in your query you need to set all variables to ?'s. So your query on line 147/148 should look like this: preparedStatement = con.prepareStatement("SELECT * FROM Warner Player = ?"); Then, afterwards you need to bind the values to the parameters and finally you can execute the query. Like this: preparedStatement.setString(1, target.getName()); ResultSet rs = preparedStatement.executeQuery(); Here's a tutorial for using prepared statements: http://www.jdbc-tutorial.com/jdbc-prepared-statements.htm
You have to do your ResultSet operations before you close the statements and connection. As long as you're not returning the ResultSet for further operations then you should use a finally clause. Like this: Code:java try { ...}catch (Exception ex) { ...}finally { rs.close(); pstmnt.close();} The finally clause will always be executed after the try/catch so you should use it to clean up your connections when you're done using them. If that doesn't help try putting this in your catch statements: Code:java ex.printStackTrace(); For debugging purposes.
i tried around abit, and found out that the connection is null :/ even tho it says that it's connected...
Ok, I looked over more of your code. In the database package your declaring all variables and methods as static. But, then your constructing an object of each class in the main class. So to fix the connection being null take off all the static declarations. Also, there's no reason to separate the GetDatabaseData class and DatabaseSetup class.
well, i can get it to work in the DatabaseSetup class, but not the GetDatabaseData, so that might fix it