Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.*;
- public class SQLOperations {
- private Connection connect = null;
- private Statement statement = null;
- public SQLOperations() {}
- public boolean connectToDatabase() {
- boolean ifConnected = false;
- String url = "jdbc:mysql://sql11.freemysqlhosting.net:3306/sql11175412?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8";
- String user = "sql11175412" ;
- String password = "--------------";
- try {
- Class.forName("com.mysql.jdbc.Driver");
- connect = DriverManager.getConnection(url, user, password);
- statement = connect.createStatement();
- ifConnected = true;
- }
- catch (SQLException | ClassNotFoundException exc) {
- PopUpAsker.displayInformerPopup("Nie udalo sie polaczyc z baza danych na serwerze. Sprawdz polaczenie z Internetem.");
- return ifConnected;
- }
- return ifConnected;
- }
- public Statement getStatement() {
- return this.statement;
- }
- public void executeStatement(String sqlCode) {
- try {
- statement.executeUpdate(sqlCode);
- }
- catch (SQLException exc) {
- PopUpAsker.displayInformerPopup("Nie udalo sie wykonac polecenia");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement