Advertisement
Jakebooy9

MySQL Test

Jul 12th, 2016
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. java.sql.Connection connection = null;
  2. java.sql.Statement statement = null;
  3. try {
  4. connection = java.sql.DriverManager.getConnection("jdbc:mysql://localhost:3306/test?user=root&password=");
  5.  
  6. statement = connection.createStatement();
  7.  
  8. String sql = "SELECT username, points FROM test";
  9.  
  10. java.sql.ResultSet rs = statement.executeQuery(sql);
  11.  
  12. while (rs.next()) {
  13. String name = rs.getString("username");
  14. int points = rs.getInt("points");
  15. plugin.getServer().broadcastMessage("Name: " + name + "; Points: " + points);
  16. }
  17.  
  18. }catch(java.sql.SQLException e){
  19. e.printStackTrace();
  20. }finally{
  21. try {
  22. if(statement!=null){
  23. statement.close();
  24. }
  25. }catch(java.sql.SQLException e){
  26. e.printStackTrace();
  27. }
  28. }
  29. try {
  30. if (connection != null) {
  31. connection.close();
  32. }
  33. }catch(java.sql.SQLException e){
  34. e.printStackTrace();
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement