Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MySQL {
- private String HOST = "";
- private String DATABASE = "";
- private String USER = "";
- private String PASSWORD = "";
- private Connection con;
- public MySQL(String host, String database, String user, String password) {
- this.HOST = host;
- this.DATABASE = database;
- this.USER = user;
- this.PASSWORD = password;
- }
- public void connect() {
- try {
- this.con = ((Connection) DriverManager.getConnection("jdbc:mysql://" + this.HOST + ":3306/" + this.DATABASE + "?autoReconnect=true", this.USER, this.PASSWORD));
- } catch (Exception localException) {
- }
- }
- public void close() {
- try {
- if (this.con != null) {
- this.con.close();
- }
- } catch (Exception localException) {
- }
- }
- public void update(String qry) {
- try {
- Statement st = (Statement) this.con.createStatement();
- st.executeUpdate(qry);
- st.close();
- } catch (Exception localException) {
- }
- }
- public ResultSet query(String qry) {
- ResultSet rs = null;
- try {
- Statement st = (Statement) this.con.createStatement();
- rs = st.executeQuery(qry);
- } catch (Exception localException) {
- }
- return rs;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement