Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.eliteSchwein.PRcore_addon;
- import java.io.PrintStream;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import com.mysql.jdbc.Driver;
- public class MySQL
- {
- private String Host;
- private String Database;
- private String Username;
- private String Password;
- private Connection connection;
- public MySQL(String host, String database, String username, String password)
- {
- this.Host = host;
- this.Database = database;
- this.Username = username;
- this.Password = password;
- }
- public void Connect()
- {
- try
- {
- Class.forName("com.mysql.jdbc.Driver");
- }
- catch (ClassNotFoundException e1)
- {
- System.out.println("[MySQLAPI] Fehler 01");
- System.out.println("[MySQLAPI] Es fehlen benoetigte Klassen!");
- e1.printStackTrace();
- }
- String url = "jdbc:mysql://138.201.145.228:3306/PRmoney" + this.Database;
- try
- {
- this.connection = DriverManager.getConnection("jdbc:mysql://PureResolution.net/PRmoney", "", "");
- }
- catch (SQLException e2)
- {
- System.out.println("[MySQLAPI] Fehler 02");
- System.out.println("[MySQLAPI] Es ist ein Fehler bei der Verbindung aufgetreten!");
- e2.printStackTrace();
- }
- }
- public void Disconnect()
- {
- try
- {
- if ((!this.connection.isClosed()) && (this.connection != null))
- {
- this.connection.close();
- System.out.println("[MySQLAPI] Die Verbindung zum MySQL-Server wurde erfolgreich getrennt!");
- }
- else
- {
- System.out.println("[MySQLAPI] Die Verbindung ist bereits getrennt!");
- }
- }
- catch (SQLException e3)
- {
- System.out.println("[MySQLAPI] Fehler 03");
- System.out.println("[MySQLAPI] Es ist ein Fehler beim trennen der Verbindung aufgetreten!");
- e3.printStackTrace();
- }
- }
- public ResultSet GetResult(String command)
- {
- try
- {
- if (this.connection.isClosed()) {
- Connect();
- }
- Statement st = this.connection.createStatement();
- st.executeQuery(command);
- return st.getResultSet();
- }
- catch (SQLException e4)
- {
- System.out.println("[MySQLAPI] Fehler 04");
- System.out.println("[MySQLAPI] Es ist ein Fehler beim Ausfuehren des Befehls aufgetreten!");
- e4.printStackTrace();
- }
- return null;
- }
- public void ExecuteCommand(String command)
- {
- try
- {
- if (this.connection.isClosed()) {
- Connect();
- }
- Statement st = this.connection.createStatement();
- st.executeUpdate(command);
- }
- catch (SQLException e5)
- {
- System.out.println("[MySQLAPI] Fehler 04");
- System.out.println("[MySQLAPI] Es ist ein Fehler beim Ausfuehren des Befehls aufgetreten!");
- e5.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement