Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.triblion.spigot;
- import org.bukkit.plugin.java.JavaPlugin;
- import java.sql.*;
- import java.util.ArrayList;
- import java.util.List;
- public class Test extends JavaPlugin {
- private Connection connection;
- private String host, database, username, password
- private int port;
- @Override
- public void onEnable() {
- host = "localhost";
- port = 3306;
- database ="FrozenSuite";
- username = "test";
- password = "Password";
- try {
- Connect();
- Statement statement = connection.createStatement();
- ResultSet result = statement.executeQuery("SELECT * FROM Players WHERE balance = 0;");
- List<String> playersBalance = new ArrayList<String>();
- while (result.next()) {
- String name = result.getString("PlayerName");
- playersBalance.add(name);
- }
- statement.executeUpdate("INSERT INTO Players (PlayerName, balance ) VALUES ('PlayerName', 100);");
- } catch (SQLException e) {
- e.printStackTrace();
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- }
- }
- @Override
- public void onDisable() {
- }
- private void Connect() throws SQLException, ClassNotFoundException {
- if (connection !=null && !connection.isClosed()) {
- return;
- }
- synchronized (this) {
- if(connection !=null && !connection.isClosed()) {
- return;
- }
- Class.forName("com.mysql.jdbc.Driver");
- connection = DriverManager.getConnection("jdbc:mysql://" + this.host + ":" + this.port + "/" + this.database, this.username, this.password);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement