Advertisement
Guest User

Untitled

a guest
May 19th, 2017
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. import java.sql.*;
  2.  
  3. public class SQLOperations {
  4. private Connection connect = null;
  5. private Statement statement = null;
  6.  
  7. public SQLOperations() {}
  8.  
  9. public boolean connectToDatabase() {
  10. boolean ifConnected = false;
  11. String url = "jdbc:mysql://sql11.freemysqlhosting.net:3306/sql11175412?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8";
  12. String user = "sql11175412" ;
  13. String password = "--------------";
  14. try {
  15. Class.forName("com.mysql.jdbc.Driver");
  16. connect = DriverManager.getConnection(url, user, password);
  17. statement = connect.createStatement();
  18. ifConnected = true;
  19. }
  20. catch (SQLException | ClassNotFoundException exc) {
  21. PopUpAsker.displayInformerPopup("Nie udalo sie polaczyc z baza danych na serwerze. Sprawdz polaczenie z Internetem.");
  22. return ifConnected;
  23. }
  24. return ifConnected;
  25. }
  26.  
  27. public Statement getStatement() {
  28. return this.statement;
  29. }
  30.  
  31. public void executeStatement(String sqlCode) {
  32. try {
  33. statement.executeUpdate(sqlCode);
  34. }
  35. catch (SQLException exc) {
  36. PopUpAsker.displayInformerPopup("Nie udalo sie wykonac polecenia");
  37. }
  38. }
  39.  
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement