Mysql??

Discussion in 'Plugin Development' started by GRANTSWIM4, Jan 2, 2013.

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

    GRANTSWIM4

    How do i put mysql in my plugin

    and can mysql send emails i know bukkit can but im just asking
     
  2. Offline

    fireblast709

    MySQL cannot send emails, Java can
     
  3. Offline

    GRANTSWIM4

    Ok How do i put mysql in my plugin then
     
  4. Offline

    fireblast709

    Code:java
    1. Connection con = null;
    2. Statement stmt = null;
    3. ResultSet result = null;
    4. try
    5. {
    6. con = DriverManager.getConnection("jdbc:mysql://iport/database");
    7. stmt = con.createStatement();
    8. result = stmt.executeQuery("SELECT * FROM table");
    9. if(result.next())
    10. {
    11. int columnNumber = 0;
    12. int someNumber = result.getInt("columnname");
    13. String someString = result.getString(columnNumber);
    14. }
    15. else
    16. {
    17. // Empty ResultSet, aka no columns
    18. }
    19. }
    20. catch (SQLException ex)
    21. {
    22. this.getLogger().warning("An SQL exception occurred: "+ex.getMessage());
    23. }
    24. finally
    25. {
    26. if(result != null)
    27. {
    28. result.close();
    29. }
    30. if(stmt != null)
    31. {
    32. stmt.close();
    33. }
    34. if(con != null)
    35. {
    36. con.close();
    37. }
    38. }

    A very basic snippet. I am not sure about the url (if it is "jdbc:mysql://")
     
  5. Offline

    GRANTSWIM4

    Thx this will help me alot can you print the output of a bukkit event and put it up on mysql?
     
  6. Offline

    jbman223

    fireblast709 You are correct on the URL. If possible, make sure you run your MySQL in a separate thread so that it doesn't lag the game.
     
  7. Offline

    GRANTSWIM4

  8. Offline

    fireblast709

    #CastawayDev @ esper.net
     
  9. Offline

    GRANTSWIM4

    Im on
     
  10. Offline

    fireblast709

    and answered
     
  11. Offline

    iZanax

    fireblast709
    Should the Connection not be closed after the query is pulled ( } finally {) ?
    Or is this automaticly done?
    con.close()
     
    fireblast709 likes this.
  12. Offline

    fireblast709

    yes true
     
  13. Offline

    iZanax

    One question left. fireblast709
    Should stmt and result be closed as well?
    or this will close as well when con is closed?
     
    fireblast709 likes this.
  14. Offline

    fireblast709

    you are all right. Though in Java 7 this is not needed anymore (since they have try-with-resources and auto closable resources). But as we have 1.5/1.6 as standard, they still need to be closed manually
     
  15. Offline

    iZanax

    Dangit.
    I will play safe.
    By closing all three by finally { part
    Thanks again :3
     
  16. Offline

    fireblast709

    fixed the other post btw ;3. If Bukkit is in Java 5, I go with Java 5
     
    iZanax likes this.
Thread Status:
Not open for further replies.

Share This Page