Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.*;
- public class MySQL {
- private String host, database, user, password;
- private int port;
- private Connection con;
- public MySQL(String host, String database, String user, String password, int port) {
- this.host = host;
- this.database = database;
- this.user = user;
- this.password = password;
- this.port = port;
- }
- /**
- * Verbindung aufbauen mit JDBC Driver
- */
- public void connect() {
- try {
- con = DriverManager.getConnection("jdbc:mysql://" + this.host + ":" + this.port + "/" + this.database + "?" +
- "autoReconnect=true", this.user, this.password);
- } catch (Exception e) {
- }
- }
- /**
- * Verbindung schließen
- */
- public void close() {
- try {
- if (con != null) {
- con.close();
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- /**
- * DB-Anfrage
- */
- public void update(String qry) {
- try {
- Statement st = con.createStatement();
- st.executeUpdate(qry);
- st.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- /**
- * DB-Manipulation
- */
- public ResultSet query(String qry) {
- ResultSet rs = null;
- try {
- Statement st = con.createStatement();
- rs = st.executeQuery(qry);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return rs;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement