Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MySQL {
- public static String host = "TrySoul.de";
- public static String database = "db";
- public static String user = "root";
- public static String password = "123456";
- private static Connection con;
- public MySQL() {
- connect();
- }
- public static void connect() {
- try {
- con = DriverManager.getConnection("jdbc:mysql://" + host + ":3306/" + database + "?autoReconnect=true", user, password);
- System.out.println("[MySQL] Erfolgreich verbunden.");
- } catch (SQLException ex) {
- ex.printStackTrace();
- System.out.println("[MySQL] Verbinden fehlgeschlagen!");
- }
- }
- public static void close() {
- try {
- if(con != null) {
- con.close();
- }
- } catch(SQLException ex) {
- ex.printStackTrace();
- }
- }
- public static ResultSet query(String qry) {
- ResultSet rs = null;
- try {
- Statement st = con.createStatement();
- rs = st.executeQuery(qry);
- } catch(SQLException ex) {
- connect();
- ex.printStackTrace();
- }
- return rs;
- }
- public static void update(String qry) {
- try {
- Statement st = con.createStatement();
- st.executeUpdate(qry);
- st.close();
- } catch(SQLException ex) {
- connect();
- ex.printStackTrace();
- }
- }
- public static Connection getConnection(){
- return con;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement