Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static String username = "root";
- public static String passwort = "ByteDanoNiklas15845filoumarkSyloxseineMutteristFett";
- public static String host = "localhost";
- public static int port = 3306;
- public static String database = "Ts3Support";
- public static Connection con;
- public static void connect() {
- if(!isConnected()) {
- try {
- con = DriverManager.getConnection("jdbc:mysql://"+host+":"+port+"/"+database, username, passwort);
- System.out.println("[MySQL] Die MySQL verbindung ist erfolgt!");
- } catch (SQLException e) {
- e.printStackTrace();
- System.out.println("[MySQL] Es konnte keine Verbindung hergestellt werden..");
- }
- }
- }
- public static void close() {
- if(!isConnected()) {
- try {
- con.close();
- System.out.println("[MySQL] Die Verbindung wurde geschlossen!");
- } catch (SQLException e) {
- e.printStackTrace();
- System.out.println("[MySQL] Es wurde keine offene Verbindung gefunden!");
- }
- }
- }
- public static boolean isConnected() {
- return con != null;
- }
- public static void update(String qry) {
- try {
- PreparedStatement ps = con.prepareStatement(qry);
- ps.executeUpdate();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- public static ResultSet getResult(String qry) {
- try {
- PreparedStatement ps = con.prepareStatement(qry);
- return ps.executeQuery();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- return null;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement