Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.apocalypsjenl.mysql;
- import java.sql.*;
- //MySQL Class created by ApocalypsjeNL
- public class MySQL {
- private Connection connection = null;
- public void connect(String host, Integer port, String username, String password, String database) throws SQLException, ClassNotFoundException {
- Class.forName("com.mysql.jdbc.Driver");
- connection = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database, username, password);
- }
- public void execute(String sql) throws SQLException {
- if(connection != null) {
- Statement statement = connection.createStatement();
- statement.execute(sql);
- }
- }
- public ResultSet executeQuery(String sql) throws SQLException {
- if(connection != null) {
- Statement statement = connection.createStatement();
- return statement.executeQuery(sql);
- }
- return null;
- }
- public void disconnect() throws SQLException {
- if(connection != null) {
- connection.close();
- System.out.println("Disconnected from database!");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement