Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.crocstar47.Driver;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- public class MySQL_Driver {
- private String Hostname;
- private String Username;
- private String Password;
- private String Database;
- private String Port;
- private Connection connection;
- public MySQL_Driver(String Hostname, String Username, String Password, String Database, String Port)
- {
- this.Hostname = Hostname;
- this.Username = Username;
- this.Password = Password;
- this.Database = Database;
- this.Port = Port;
- MySQL_Driver_Connect();
- }
- public void MySQL_Driver_Connect()
- {
- try
- {
- connection = DriverManager.getConnection("jdbc:mysql://" + Hostname + ":" + Port + "/" + Database + "?autoReconnect=true", Username, Password);
- System.out.println("MySQL: Erfolgreich Verbunden!");
- } catch(SQLException ex)
- {
- System.out.println("MySQL: Verbindung Fehlgeschlagen!");
- }
- }
- public void MySQL_Driver_Close()
- {
- try
- {
- if(connection != null)
- {
- connection.close();
- System.out.println("MySQL: Erfolgreich Verbindung aufgehoben!");
- }
- } catch(SQLException ex)
- {
- System.out.println("MySQL: Verbindung aufheben Fehlgeschlagen!");
- }
- }
- public void MySQL_Driver_Update(String qry)
- {
- try
- {
- Statement st = connection.createStatement();
- st.executeQuery(qry);
- st.close();
- } catch(SQLException ex)
- {
- MySQL_Driver_Connect();
- }
- }
- public ResultSet MySQL_Driver_Query(String qry)
- {
- ResultSet rs = null;
- try
- {
- Statement st = connection.createStatement();
- rs = st.executeQuery(qry);
- } catch(SQLException ex)
- {
- MySQL_Driver_Connect();
- }
- return rs;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement