Fetching and setting to MySQL

Discussion in 'Plugin Development' started by Markyroson, May 28, 2015.

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

    Markyroson

    How do you go about fetching and setting information to a MySQL database (ie player stats/currency amounts) within Java?
     
    Last edited: May 28, 2015
  2. Offline

    Konato_K

    @Markyroson "posting" is probably not the right word, anyway, have you tried using google? There are thousands of examples out there.
     
  3. Offline

    Zombie_Striker

  4. Offline

    Markyroson

    I changed the title and my original post to the correct terminology (changed "posting" to "setting"). I was just wondering if the community here had a better example than youtube videos and a couple of websites that had full out ones (was wondering especially after seeing bashing of youtube videos on forums).
     
  5. Offline

    Konato_K

    @Markyroson Youtube videos are horrible, to be honest I would go with the Oracle Tutorials and maybe one or another site that has stuff right.

    As a note, you should read about Prepared Statements to increase performance and prevent sql injection.
     
    Markyroson likes this.
  6. Offline

    Markyroson

    I did find a website that seemed to have it but I cannot find it on this PC (found it on mobile so will look there later) and I will post it in here.

    I will look into prepared statements. How do they increase performance though?
     
  7. Offline

    timtower Administrator Administrator Moderator

    @Markyroson They protect against sql injection (something that could destroy your database at least)
    And they are just easier to use instead of normal queries (have experience with both methods)
     
    Markyroson likes this.
  8. Offline

    Konato_K

    @Markyroson The prepared statements are sent to the database and pre-compiled there, and can be used multiple times.

    Doing something like this would be faster than creating a new statement for each query.
    Code:
    for(Data data : dataList) {
       preparedStatement .setInt(1, data.getId());
       preparedStatement.setString(2, data.getValue();
       preparedStatement.executeUpdate();
    }
     
  9. Offline

    mythbusterma

    @Konato_K

    In an imperceptible way, yes that would be faster.


    @Markyroson

    The only real reason you would use prepared statements is to prevent SQL injection, a particularly common and hilarious exploit that allows someone to wipe your database.

    Also, do your queries on a separate thread, so as not to hang up the server.
     
Thread Status:
Not open for further replies.

Share This Page