Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.phill.wolf;
- import java.io.PrintStream;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- public class MySQL
- {
- public static String host = "127.0.0.1";
- public static String port = "3306";
- public static String database = "ReNet";
- public static String usrname = "root";
- public static String passwd = "WAHBEAaHfKyKKCNG";
- public static Connection con;
- public static void connect()
- {
- if (!connected()) {
- try
- {
- con = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database + "?user=" + usrname + "&password=" + passwd + "&autoReconnect=true");
- System.out.println("[PSQL] MySQL Verbindung aufgebaut!");
- }
- catch (SQLException e)
- {
- System.out.println("[PSQL] " + e.getMessage());
- }
- }
- }
- public static void disconnect()
- {
- if (connected()) {
- try
- {
- con.close();
- System.out.println("[PSQL] MySQL Verbindung geschlossen!");
- }
- catch (SQLException e)
- {
- e.printStackTrace();
- }
- }
- }
- public static boolean connected()
- {
- return con != null;
- }
- public static void update(String qry)
- {
- try
- {
- PreparedStatement statement = con.prepareStatement(qry);
- statement.executeUpdate();
- statement.close();
- }
- catch (SQLException e)
- {
- e.printStackTrace();
- }
- }
- public static ResultSet query(String qry)
- {
- ResultSet rs = null;
- try
- {
- Statement st = con.createStatement();
- rs = st.executeQuery(qry);
- }
- catch (SQLException e)
- {
- e.printStackTrace();
- }
- return rs;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement