Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Hier der Fehler
- Exception in thread "main" java.lang.NullPointerException
- at -----.mysql.Main.mysqlcon(Main.java:20)
- at -----.mysql.Main.main(Main.java:24)
- Process finished with exit code 1
- //Das ist die Main Classe
- package -----.mysql;
- import com.github.theholywaffle.teamspeak3.TS3Api;
- import com.github.theholywaffle.teamspeak3.TS3Config;
- import com.github.theholywaffle.teamspeak3.TS3Query;
- import java.util.logging.Level;
- public class Main {
- public static final TS3Config config = new TS3Config();
- public static final TS3Query query = new TS3Query(config);
- public static final TS3Api api = new TS3Api(query);
- public static MySQL mysql;
- private static void mysqlcon () {
- mysql.connect();
- }
- public static void main (String[] args){
- mysqlcon();
- config.setHost("-------");
- config.setFloodRate(TS3Query.FloodRate.UNLIMITED);
- config.setDebugLevel(Level.ALL);
- query.connect();
- api.selectVirtualServerById(---);
- api.login("---", "---);
- api.setNickname("-------");
- System.out.println("Der Bot wurde erfolgreich gestartet");
- }
- }
- // Und hier die MySQL Klasse
- package radiopower.mysql;
- import java.sql.*;
- public class MySQL {
- private String HOST;
- private String DATABASE;
- private String USER;
- private String PASSWORD;
- private Connection con;
- public boolean isConnected()
- {
- return this.con != null;
- }
- public void connect()
- {
- try
- {
- this.con = DriverManager.getConnection(
- "jdbc:mysql://localhost:3306/streamplan?autoReconnect=true", "root",
- "");
- System.out.println("[MySQL] Die Verbindung zur MySQL wurde hergestellt!");
- }
- catch (SQLException e)
- {
- System.out.println("[MySQL] Die Verbindung zur MySQL ist fehlgeschlagen! Fehler: " + e.getMessage());
- }
- }
- public void close()
- {
- try
- {
- if (this.con != null)
- {
- this.con.close();
- System.out.println("[MySQL] Die Verbindung zur MySQL wurde Erfolgreich beendet!");
- }
- }
- catch (SQLException e)
- {
- System.out.println("[MySQL] Fehler beim beenden der Verbindung zur MySQL! Fehler: " + e.getMessage());
- }
- }
- public void update(String qry)
- {
- try
- {
- Statement st = this.con.createStatement();
- st.executeUpdate(qry);
- st.close();
- }
- catch (SQLException e)
- {
- connect();
- System.err.println(e);
- }
- }
- public ResultSet query(String qry)
- {
- ResultSet rs = null;
- try
- {
- rs = this.con.createStatement().executeQuery(qry);
- }
- catch (SQLException e)
- {
- connect();
- System.err.println(e);
- }
- return rs;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement