Boa tarde Pessoal,
Gostaria de saber se esta classe é eficiente ou não e o que eu poderia melhorá-la.
package util;
import java.sql.Connection;
//import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.naming.InitialContext;
import javax.sql.DataSource;
public class ConexaoUtil {
private Connection conexao;
public ConexaoUtil() {
conexao = abreConexao();
}
private Connection abreConexao() {
try {
InitialContext ctx = new InitialContext();
DataSource ds = (DataSource) ctx.lookup("java:comp/env/jdbc/bdportal");
return ds.getConnection();
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("Não foi possivel abrir a conexao", e);
}
}
public ResultSet executeConsulta(String sql) throws SQLException {
Statement st = conexao.createStatement();
return st.executeQuery(sql);
}
public int executeAtualizacao(String sql) throws SQLException {
Statement st = conexao.createStatement();
return st.executeUpdate(sql);
}
public void fechaConexao() {
try {
conexao.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}