Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package de.klschlitzohr.main;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- public class MySQL {
- public static String host = "localhost";
- public static String port = "3306";
- public static String database = "plot_db";
- public static String username = "mysql";
- public static String password = "avision";
- public static java.sql.Connection con;
- public static void connect() {
- try
- {
- con = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database, username, password);
- System.out.println("[MySQL] Connected.");
- }
- catch (SQLException e)
- {
- System.out.println("[MySQL] Connection failed.");
- e.printStackTrace();
- }
- }
- public static void disconnect() {
- if (isConnected()) {
- try {
- con.close();
- System.out.println(Utils.prefix + "MYSQL Verbindung izz weg");
- } 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 {
- java.sql.PreparedStatement ps = con.prepareStatement(qry);
- ps.executeUpdate();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- public static ResultSet getResult(String gry) {
- java.sql.PreparedStatement ps;
- try {
- ps = con.prepareStatement(gry);
- return ps.executeQuery();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- return null;
- }
- public static java.sql.Connection getConnection() {
- return con;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement