Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package br.unesp.demac.bcc.soo.agendaweb.util;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.SQLException;
- /**
- *
- * @author aluno
- */
- public class FabricaConexao implements Conexao {
- private FabricaConexao() {
- }
- public static Connection getConexao() {
- Connection con = null;
- try {
- Class.forName(DRIVER);
- con = DriverManager.getConnection(URL, USER, PASSWORD);
- } catch (ClassNotFoundException ex) {
- System.out.println("Problemas ao carregar o Driver!");
- System.out.println("ERRO: " + ex.getMessage());
- } catch (SQLException ex) {
- System.out.println("Problemas ao autenticar!");
- System.out.println("ERRO: " + ex.getMessage());
- }
- return con;
- }
- public static void fechar(Connection con) {
- try {
- con.close();
- } catch (SQLException ex) {
- System.out.println("Problemas ao fechar: " + ex.getMessage());
- }
- }
- public static void fechar(Connection con, PreparedStatement pstm) {
- try {
- con.close();
- pstm.close();
- } catch (SQLException ex) {
- System.out.println("Problemas ao fechar: " + ex.getMessage());
- }
- }
- public static void fechar(PreparedStatement pstm) {
- try {
- pstm.close();
- } catch (SQLException ex) {
- System.out.println("Problemas ao fechar: " + ex.getMessage());
- }
- }
- }
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package br.unesp.demac.bcc.soo.agendaweb.util;
- /**
- *
- * @author aluno
- */
- public interface Conexao {
- final String DATABASE = "agendaWeb";
- final String DRIVER = "org.gjt.mm.mysql.Driver";
- final String PASSWORD = "admin";
- final String USER = "root";
- final String URL = "jdbc:mysql://localhost:3306/" + DATABASE;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement