Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package de.mrelektronz.friend.mysql;
- 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 Mysql()
- {
- }
- public static void connect()
- {
- if(!connected())
- try
- {
- con = DriverManager.getConnection((new StringBuilder("jdbc:mysql://")).append(host).append(":").append(port).append("/").append(database).toString(), usrname, passwd);
- System.out.println("[FriendSystem] MySQL Verbindung aufgebaut!");
- }
- catch(SQLException e)
- {
- System.out.println((new StringBuilder("[FriendSystem] ")).append(e.getMessage()).toString());
- }
- }
- public static void disconnect()
- {
- if(connected())
- try
- {
- con.close();
- System.out.println("[FriendSystem] 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;
- }
- public static String host;
- public static String port;
- public static String database;
- public static String usrname;
- public static String passwd;
- public static Connection con;
- }
Add Comment
Please, Sign In to add comment