Use Conversations AND jdbc together

Discussion in 'Plugin Development' started by TheA13X, Oct 14, 2013.

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

    TheA13X

    Hey Guys.
    I have a little problem with the Conversation API.
    I have to work with SQLConnections in the "acceptInput" Method.
    But at this point the Connection to the player is closing and he becomes an End of Stream Message.

    Example:
    Code:java
    1.  
    2. @Override
    3. public Prompt acceptInput(ConversationContext arg0, String arg1) {
    4. if(!arg1.equals("...")){
    5. try {
    6. PreparedStatement sql=getC().prepareStatement("UPDATE `ActivationData` SET `Land`=? WHERE `Name`=?");
    7. sql.setString(1, arg1);
    8. sql.setString(2, ((Player)arg0).getName());
    9. sql.executeUpdate();
    10. } catch (SQLException e) {
    11. e.printStackTrace();
    12. }
    13. closeConnection();
    14. return new CityPrompt();
    15. }
    16. else{
    17. try {
    18. PreparedStatement sql=getC().prepareStatement("UPDATE `ActivationData` SET `Land`=? WHERE `Name`=?");
    19. sql.setString(1, "KEINS");
    20. sql.setString(2, ((Player)arg0).getName());
    21. sql.executeUpdate();
    22. } catch (SQLException e) {
    23. e.printStackTrace();
    24. }
    25. closeConnection();
    26. return new ServerPrompt();
    27. }
    28. }
    29.  


    The first question is: Why?
    and the second : How can I avoid this strage "Error"

    Thank YOU for your answers.

    EDIT: I forgot, to say, that there isn't any Error massage. I know that the ConversationAPI is very sensitive. If there is any Exception in it, it kicks the player from ther server. But not this time.

    Looks like a new Enigma of the Bukkit API , doesn't it...

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
  2. Offline

    lycano

    Does it have to be "instantly" updated when making a choice?

    As you can chain choices the end could be "forget what i said" then you would have to rollback everything.

    What i would do is collect choices made and bind them to actions.

    That way you could even switch the backend from sql to text or whatever. I also think using this method you probably will get many connection timeouts when closing the connection after each choice made as it seems you dont use Pooled Connections (which avoids this and automatically reuses a connection if not needed).

    Anyways i would try to store choices made first before implementing sql queries to it. Check if that works and then try to implement the backend.
     
    TheA13X likes this.
  3. Offline

    TheA13X

    Thats a great Idea. Thank you! :D

    That's Bullshit. Of course there is an Exception-message which says, that I can't cast a conversationContext to Player (or the other way).
    Sorry.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
Thread Status:
Not open for further replies.

Share This Page