Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package ConnettoreMysql;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.Random;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import javax.ejb.*;
- import server.RemoteServer;
- /**
- *
- * @author kvothe
- */
- @Stateless
- public class ConnectBean1 {
- RemoteServer replica1 = new RemoteServer(false, true, true, "localhost:3306","1");
- private Connection connection;
- public ConnectBean1() {
- try {
- Class.forName("com.mysql.jdbc.Driver");
- connection
- = DriverManager
- .getConnection("jdbc:mysql://"+ replica1.getMyip()+"/progetto", "salvo", "distribuiti");
- } catch (ClassNotFoundException | SQLException ex) {
- Logger.getLogger(ConnettoreMysql.class.getName())
- .log(Level.INFO, null, ex);
- System.err.println("CONNESSIONE FALLITA");
- }
- }
- public ResultSet doQuery(String query) throws SQLException {
- Statement stm = connection.createStatement();
- return stm.executeQuery(query);
- }
- public void close() throws SQLException {
- if (!connection.isClosed()) {
- connection.close();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement