Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MySQL {
- private Connection connection;
- private PreparedStatement preparedStatement;
- private ResultSet resultSet;
- private String host;
- private int port;
- private String database;
- private String user;
- private String password;
- public MySQL(String host, int port, String database, String user, String password) {
- this.host = host;
- this.port = port;
- this.database = database;
- this.user = user;
- this.password = password;
- }
- public void connect() {
- try {
- this.connection = DriverManager.getConnection("jdbc:mysql://" + this.host + ":" + this.port + "/" + this.database + "?autoReconnect=true", this.user, this.password);
- System.out.println("[MySQL successfully connected...]");
- } catch (SQLException ex) {
- System.out.println("[MySQL successfully disconnected...]");
- }
- }
- public Connection getConnection() {
- return this.connection;
- }
- public boolean isConnected() {
- if (this.connection != null) {
- return true;
- }
- return false;
- }
- public void disconnect() {
- if (this.connection != null) {
- try {
- this.connection.close();
- } catch (SQLException ex) {
- }
- }
- }
- public void update(String update) {
- try {
- this.preparedStatement = this.connection.prepareStatement(update);
- this.preparedStatement.executeUpdate(update);
- } catch (SQLException ex) {
- }
- }
- public ResultSet select(String query) {
- try {
- this.preparedStatement = this.connection.prepareStatement(query);
- this.resultSet = this.preparedStatement.executeQuery();
- } catch (SQLException ex) {
- ex.printStackTrace();
- }
- return resultSet;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement