SHOW:
|
|
- or go back to the newest paste.
1 | - | 25.07 00:52:16 [Server] INFO at org.bukkit.craftbukkit.v1_7_R4.scheduler.CraftAsyncTask.run(CraftAsyncTask.java:53) |
1 | + | package me.sky.sql; |
2 | - | 25.07 00:52:16 [Server] INFO at org.bukkit.craftbukkit.v1_7_R4.scheduler.CraftTask.run(CraftTask.java:71) |
2 | + | |
3 | - | 25.07 00:52:16 [Server] INFO at me.sky.sql.Main$1.run(Main.java:57) |
3 | + | import java.sql.Connection; |
4 | - | 25.07 00:52:16 [Server] INFO Caused by: java.lang.NullPointerException |
4 | + | import java.sql.DriverManager; |
5 | - | 25.07 00:52:16 [Server] INFO at java.lang.Thread.run(Thread.java:745) |
5 | + | import java.sql.PreparedStatement; |
6 | - | 25.07 00:52:16 [Server] INFO at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) |
6 | + | import java.sql.ResultSet; |
7 | - | 25.07 00:52:16 [Server] INFO at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) |
7 | + | import java.sql.SQLException; |
8 | - | 25.07 00:52:16 [Server] INFO at org.bukkit.craftbukkit.v1_7_R4.scheduler.CraftAsyncTask.run(CraftAsyncTask.java:56) |
8 | + | import java.util.logging.Level; |
9 | - | 25.07 00:52:16 [Server] WARN org.apache.commons.lang.UnhandledException: Plugin DumbMYSQL v0.0.0.0.1 generated an exception while executing task 178 |
9 | + | import java.util.logging.Logger; |
10 | - | 25.07 00:52:16 [Server] WARN Exception in thread "Craft Scheduler Thread - 33" |
10 | + | import org.bukkit.Bukkit; |
11 | import org.bukkit.event.EventHandler; | |
12 | import org.bukkit.event.EventPriority; | |
13 | import static org.bukkit.event.EventPriority.HIGHEST; | |
14 | import org.bukkit.event.Listener; | |
15 | import org.bukkit.event.player.PlayerJoinEvent; | |
16 | import org.bukkit.plugin.Plugin; | |
17 | import org.bukkit.plugin.java.JavaPlugin; | |
18 | ||
19 | public class Main extends JavaPlugin | |
20 | implements Listener { | |
21 | ||
22 | //Variables | |
23 | private static Connection connection; | |
24 | private static ResultSet lastQueryResult; | |
25 | ||
26 | // | |
27 | //Basic Bukkit Stuff | |
28 | @Override | |
29 | public void onEnable() { | |
30 | System.out.println("Enabled."); | |
31 | connect(); | |
32 | ||
33 | getServer().getPluginManager().registerEvents(this, this); | |
34 | } | |
35 | ||
36 | public void onDisable() { | |
37 | System.out.println("Disabled."); | |
38 | } | |
39 | // | |
40 | ||
41 | @EventHandler(priority = EventPriority.HIGHEST) | |
42 | public void onLogin(PlayerJoinEvent e) { | |
43 | executeUpdate("INSERT INTO dep (username) VALUES ("+e.getPlayer().getName()+")"); | |
44 | System.out.println("Inserted"); | |
45 | } | |
46 | // | |
47 | ||
48 | public void executeUpdate(final String query) { | |
49 | ||
50 | Bukkit.getServer().getScheduler().runTaskAsynchronously(this, new Runnable() { | |
51 | ||
52 | @Override | |
53 | public void run() { | |
54 | PreparedStatement preparedStatement = null; | |
55 | try { | |
56 | preparedStatement = connection.prepareStatement(query); | |
57 | preparedStatement.executeUpdate(); | |
58 | } catch (SQLException exception) { | |
59 | } finally { | |
60 | try { | |
61 | if (preparedStatement != null) { | |
62 | preparedStatement.close(); | |
63 | } | |
64 | } catch (SQLException exception) { | |
65 | } | |
66 | } | |
67 | } | |
68 | }); | |
69 | } | |
70 | ||
71 | public void connect() { | |
72 | Bukkit.getScheduler().runTaskAsynchronously(this, new Runnable() { | |
73 | ||
74 | @Override | |
75 | public void run() { | |
76 | try { | |
77 | Class.forName("com.mysql.jdbc.Driver"); | |
78 | connection = DriverManager.getConnection("jdbc:mysql://" + "xxxxx" + ":" + "3306" + "/" + "db", "xxxx", "xxxxx"); | |
79 | System.out.println("Successfully connected to database..."); | |
80 | ||
81 | } catch (ClassNotFoundException | SQLException exception) { | |
82 | //Util.throwErrorMessage("Encountered error whilst connecting to database..."); | |
83 | } | |
84 | } | |
85 | }); | |
86 | } | |
87 | ||
88 | } |