Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.*;
- /**
- * Created by Felix on 18.02.2017.
- */
- public class MysqlDriver {
- private String host;
- private int port;
- private String database;
- private String username;
- private String password;
- private Connection connection;
- public void connect(){
- try {
- connection = DriverManager.getConnection("jdbc:mysql://"+host+":"+port+"/"+database+"?autoReconnect=true", username, password);
- System.out.println("[CloudSystem]MySQL verbunden!");
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- public void disconnect(){
- if(isConnected()){
- try {
- connection.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public void update(String qry){
- try {
- PreparedStatement preparedStatement = connection.prepareStatement(qry);
- preparedStatement.executeUpdate();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- public ResultSet getResultSet(String qry){
- try {
- PreparedStatement preparedStatement = connection.prepareStatement(qry);
- return preparedStatement.executeQuery();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- return null;
- }
- public boolean isConnected(){
- return (connection == null ? false : true);
- }
- public Connection getConnection() {
- return connection;
- }
- public void setConnection(Connection connection) {
- this.connection = connection;
- }
- public String getHost() {
- return host;
- }
- public void setHost(String host) {
- this.host = host;
- }
- public int getPort() {
- return port;
- }
- public void setPort(int port) {
- this.port = port;
- }
- public String getDatabase() {
- return database;
- }
- public void setDatabase(String database) {
- this.database = database;
- }
- public String getUsername() {
- return username;
- }
- public void setUsername(String username) {
- this.username = username;
- }
- public String getPassword() {
- return password;
- }
- public void setPassword(String password) {
- this.password = password;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement