Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- *
- */
- package supportManager;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- /**
- * @author Gamer08 30.10.2017
- */
- public class MysqlConnection {
- public static String host = "localhost";
- public static String port = "3306";
- public static String database = "tickets";
- public static String username = "root";
- public static String password = "";
- public static Connection con;
- public static boolean isConnected() {
- return con != null;
- }
- public static void connect() {
- if (!isConnected()) {
- try {
- con = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database + "?autoReconnect=true", username,password);
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
- public static void disconnect() {
- try {
- con.close();
- } catch (SQLException e) {
- }
- }
- public static PreparedStatement getStatement(String sql) {
- if (isConnected()) {
- PreparedStatement ps;
- try {
- ps = con.prepareStatement(sql);
- return ps;
- } catch (SQLException e) {
- // TODO: handle exception
- e.printStackTrace();
- }
- }
- return null;
- }
- public static ResultSet getResult(String sql) {
- if (isConnected()) {
- PreparedStatement ps;
- ResultSet rs;
- try {
- ps = getStatement(sql);
- rs = ps.executeQuery();
- return rs;
- } catch (SQLException e) {
- // TODO: handle exception
- e.printStackTrace();
- }
- }
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement