Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.scrap.mysqlmanager;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- public class MySQLConnection {
- public Connection connection;
- public Statement statement;
- public String host;
- public String db;
- public String user;
- public String pw;
- public int port;
- public MySQLConnection(String host, String db, String user, String pw, int port) {
- this.host = host;
- this.db = db;
- this.user = user;
- this.pw = pw;
- }
- public void openConnection() throws SQLException, ClassNotFoundException {
- try {
- if (connection != null && !connection.isClosed()) {
- return;
- }
- synchronized (this) {
- if (connection != null && !connection.isClosed()) {
- return;
- }
- Class.forName("com.mysql.jdbc.Driver");
- connection = DriverManager.getConnection("jdbc:mysql://" + this.host+ ":" + this.port + "/" + this.db, this.user, this.pw);
- statement = connection.createStatement();
- }
- }catch (ClassNotFoundException e) {
- e.printStackTrace();
- }catch (SQLException e) {
- e.printStackTrace();
- }
- }
- public void setData(String table, String data, String valuename, String value) throws SQLException {
- try {
- statement.executeUpdate("INSERT INTO " + table + data + " VALUES ('" + valuename + "', " + value + ");");
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- public ResultSet getData(String table, String data, String valuename) throws SQLException {
- try {
- ResultSet result = statement.executeQuery("SELECT * FROM PlayerData WHERE BALANCE = 0;");
- return result;
- } catch (SQLException e) {
- e.printStackTrace();
- return null;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement