Advertisement
Guest User

Untitled

a guest
Feb 18th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. import java.sql.*;
  2.  
  3. /**
  4. * Created by Felix on 18.02.2017.
  5. */
  6. public class MysqlDriver {
  7.  
  8. private String host;
  9. private int port;
  10. private String database;
  11. private String username;
  12. private String password;
  13. private Connection connection;
  14.  
  15. public void connect(){
  16. try {
  17. connection = DriverManager.getConnection("jdbc:mysql://"+host+":"+port+"/"+database+"?autoReconnect=true", username, password);
  18. System.out.println("[CloudSystem]MySQL verbunden!");
  19. } catch (SQLException e) {
  20. e.printStackTrace();
  21. }
  22. }
  23.  
  24. public void disconnect(){
  25. if(isConnected()){
  26. try {
  27. connection.close();
  28. } catch (SQLException e) {
  29. e.printStackTrace();
  30. }
  31. }
  32.  
  33. }
  34.  
  35. public void update(String qry){
  36. try {
  37. PreparedStatement preparedStatement = connection.prepareStatement(qry);
  38. preparedStatement.executeUpdate();
  39. } catch (SQLException e) {
  40. e.printStackTrace();
  41. }
  42. }
  43.  
  44. public ResultSet getResultSet(String qry){
  45. try {
  46. PreparedStatement preparedStatement = connection.prepareStatement(qry);
  47. return preparedStatement.executeQuery();
  48. } catch (SQLException e) {
  49. e.printStackTrace();
  50. }
  51.  
  52. return null;
  53. }
  54.  
  55. public boolean isConnected(){
  56. return (connection == null ? false : true);
  57. }
  58.  
  59. public Connection getConnection() {
  60. return connection;
  61. }
  62.  
  63. public void setConnection(Connection connection) {
  64. this.connection = connection;
  65. }
  66.  
  67. public String getHost() {
  68. return host;
  69. }
  70.  
  71. public void setHost(String host) {
  72. this.host = host;
  73. }
  74.  
  75. public int getPort() {
  76. return port;
  77. }
  78.  
  79. public void setPort(int port) {
  80. this.port = port;
  81. }
  82.  
  83. public String getDatabase() {
  84. return database;
  85. }
  86.  
  87. public void setDatabase(String database) {
  88. this.database = database;
  89. }
  90.  
  91. public String getUsername() {
  92. return username;
  93. }
  94.  
  95. public void setUsername(String username) {
  96. this.username = username;
  97. }
  98.  
  99. public String getPassword() {
  100. return password;
  101. }
  102.  
  103. public void setPassword(String password) {
  104. this.password = password;
  105. }
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement