Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package mpack;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- public class MySQL {
- public static String host = "snapecrafter.bplaced.net";
- public static String port = "3306";
- public static String database = "snapecrafter";
- public static String username = "snapecrafter";
- public static String password = "*************";
- public static Connection con;
- public static void connect() {
- if(!isConnected()) {
- try {
- con = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database,username,password);
- System.out.println("[MySQL] Verbindung aufgebaut!");
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
- public static void disconnect() {
- if(isConnected()) {
- try {
- con.close();
- System.out.println("[MySQL] Verbindung geschlossen!");
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
- public static boolean isConnected() {
- return (con == null ? false : true);
- }
- public static void update(String qry) {
- try {
- PreparedStatement ps = con.prepareStatement(qry);
- ps.executeUpdate();
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- public static ResultSet getResult(String qry) {
- PreparedStatement ps;
- try {
- ps = con.prepareStatement(qry);
- return ps.executeQuery();
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement