MqSql + Java help !

Discussion in 'Plugin Development' started by stelar7, Oct 23, 2011.

Thread Status:
Not open for further replies.
  1. Offline

    stelar7

  2. Offline

    KabOOm 356

    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
     
  3. Offline

    stelar7

    i tried that, still fails... (updated code is on github)

    Every query somehow fails...
     
  4. Offline

    KabOOm 356

    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
    1. try {
    2. ...
    3. }
    4. catch (Exception ex) {
    5. ...
    6. }
    7. finally {
    8. rs.close();
    9. pstmnt.close();
    10. }

    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
    1. ex.printStackTrace();

    For debugging purposes.

     
  5. Offline

    stelar7

    i tried around abit, and found out that the connection is null :/
    even tho it says that it's connected...
     
  6. Offline

    stelar7

    bump!, i really need help with this...
     
  7. Offline

    KabOOm 356

    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.
     
  8. Offline

    stelar7

    well, i can get it to work in the DatabaseSetup class, but not the GetDatabaseData, so that might fix it :D
     
  9. Offline

    KabOOm 356

    If you need any help with rewriting it just PM me.
     
  10. Offline

    stelar7

    sure, I'd love some help with this :D
     
Thread Status:
Not open for further replies.

Share This Page