jdbc returning data

Discussion in 'Plugin Development' started by flevas, Jan 10, 2014.

Thread Status:
Not open for further replies.
  1. Hey, im using jdbc for my plugin and i ineed to return data from mysql in the chat. Any idea how to do it?
     
  2. What are you using JDBC for?
     
  3. Offline

    xBlackLightx

    flevas
    Well to start, it may make things a bit easier if you use this:

    http://dev.mysql.com/downloads/connector/j/

    Second, you'll need to write a MySQL query to pull the information out of the database. It's not too hard. Google it if you need to, you'll find plenty of information.
    After you get the data from the database, it's super simple to print it out in the chat. Let me know if you need any more help.
    Louis1234567890987654321
    JDBC is a Java Database Connector. He's using it to connect to his MySQL database.
     
    flevas likes this.
  4. ik what is JDBC, but im asking him what is he using the Connector for :p (leaderboards? economy?)
     
  5. Offline

    xBlackLightx

  6. imporing data to mysql, reports specificaly. I want to readthem inside the server and not from the webpanel


    Yeah i know about queries, i've done it before with php also im successfuly importing data to mysql but i want to print them out now
     
  7. Simply use a ResultSet.

    A resultset is generated after a query.

    Code:
    Statement s = connection.createStatement();
    ResultSet rs = s.executeQuery("SELECT * FROM SOMETHING");
    //so do something
    rs.close();
    s.close();
     
  8. Offline

    xBlackLightx

    Alright. Instead of typing it all out myself, I have found a thread that describes in great detail, and probably a little bit better than I could. Here's a link:

    Using MySQL In your plugin

    Hope it helps. After this, if you have any further questions, feel free to ask. :)
    flevas
     
  9. Mine looks like this:
    Code:java
    1. try{
    2. Connection conn = DriverManager.getConnection(this.url, this.user, this.pass);
    3. PreparedStatement query = conn.prepareStatement("");
    4. query.executeUpdate();
    5. query.close();
    6. conn.close();
    7. }
     
  10. You need to create another statement to query the DB.
     
  11. Can you write an example? this is my first plugin and first time coding in java :D
     
  12. Code:
    Statement s = connection.createStatement();
    ResultSet rs = s.executeQuery("SELECT * FROM SOMETHING");
    if(rs.next()){  //rs.next() checks if there is more data next
        //something is in the query
        String str=rs.getString(databaseTableSomethingName);
    }else{
        //things are not found
    }
    rs.close();
    s.close();
    If you want to manage multiple data, just loop through rs.next()
     
Thread Status:
Not open for further replies.

Share This Page