Advertisement
Guest User

Untitled

a guest
Apr 26th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.10 KB | None | 0 0
  1. //Hier der Fehler
  2. Exception in thread "main" java.lang.NullPointerException
  3. at -----.mysql.Main.mysqlcon(Main.java:20)
  4. at -----.mysql.Main.main(Main.java:24)
  5.  
  6. Process finished with exit code 1
  7.  
  8. //Das ist die Main Classe
  9. package -----.mysql;
  10.  
  11. import com.github.theholywaffle.teamspeak3.TS3Api;
  12. import com.github.theholywaffle.teamspeak3.TS3Config;
  13. import com.github.theholywaffle.teamspeak3.TS3Query;
  14.  
  15. import java.util.logging.Level;
  16.  
  17. public class Main {
  18.  
  19.  
  20. public static final TS3Config config = new TS3Config();
  21. public static final TS3Query query = new TS3Query(config);
  22. public static final TS3Api api = new TS3Api(query);
  23. public static MySQL mysql;
  24.  
  25. private static void mysqlcon () {
  26. mysql.connect();
  27.  
  28. }
  29. public static void main (String[] args){
  30. mysqlcon();
  31. config.setHost("-------");
  32. config.setFloodRate(TS3Query.FloodRate.UNLIMITED);
  33. config.setDebugLevel(Level.ALL);
  34. query.connect();
  35. api.selectVirtualServerById(---);
  36. api.login("---", "---);
  37. api.setNickname("-------");
  38. System.out.println("Der Bot wurde erfolgreich gestartet");
  39. }
  40.  
  41.  
  42.  
  43. }
  44. // Und hier die MySQL Klasse
  45.  
  46. package radiopower.mysql;
  47.  
  48. import java.sql.*;
  49.  
  50. public class MySQL {
  51.  
  52. private String HOST;
  53. private String DATABASE;
  54. private String USER;
  55. private String PASSWORD;
  56. private Connection con;
  57.  
  58. public boolean isConnected()
  59. {
  60. return this.con != null;
  61. }
  62.  
  63.  
  64. public void connect()
  65. {
  66. try
  67. {
  68. this.con = DriverManager.getConnection(
  69. "jdbc:mysql://localhost:3306/streamplan?autoReconnect=true", "root",
  70. "");
  71. System.out.println("[MySQL] Die Verbindung zur MySQL wurde hergestellt!");
  72. }
  73. catch (SQLException e)
  74. {
  75. System.out.println("[MySQL] Die Verbindung zur MySQL ist fehlgeschlagen! Fehler: " + e.getMessage());
  76. }
  77. }
  78.  
  79. public void close()
  80. {
  81. try
  82. {
  83. if (this.con != null)
  84. {
  85. this.con.close();
  86. System.out.println("[MySQL] Die Verbindung zur MySQL wurde Erfolgreich beendet!");
  87. }
  88. }
  89. catch (SQLException e)
  90. {
  91. System.out.println("[MySQL] Fehler beim beenden der Verbindung zur MySQL! Fehler: " + e.getMessage());
  92. }
  93. }
  94.  
  95. public void update(String qry)
  96. {
  97. try
  98. {
  99. Statement st = this.con.createStatement();
  100. st.executeUpdate(qry);
  101. st.close();
  102. }
  103. catch (SQLException e)
  104. {
  105. connect();
  106. System.err.println(e);
  107. }
  108. }
  109.  
  110. public ResultSet query(String qry)
  111. {
  112. ResultSet rs = null;
  113. try
  114. {
  115. rs = this.con.createStatement().executeQuery(qry);
  116. }
  117. catch (SQLException e)
  118. {
  119. connect();
  120. System.err.println(e);
  121. }
  122. return rs;
  123. }
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement