package ca.uqam.projet.service;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class BD {
protected static Connection connect() {
Connection conn = null;
try {
conn = DriverManager
.getConnection("jdbc:postgresql://localhost:5432/projet",
"postgres", "collin");
conn.setAutoCommit(true);
//System.out.println("Opened database successfully");
} catch (SQLException e) {
System.err.println(e.getClass().getName() + ": " + e.getMessage());
System.exit(0);
}
return conn;
}
protected static void diconnect(Connection conn) {
try {
if (conn != null && !conn.isClosed()) {
conn.close();
conn = null;
// System.out.println("Closed database successfully");
}
} catch (SQLException e) {
System.err.println(e.getClass().getName() + ": " + e.getMessage());
System.exit(0);
}
}
protected static void CloseConnection(PreparedStatement ps) {
if (ps != null) {
try {
ps.close();
} catch (SQLException e) {
System.err.println(e.getClass().getName() + ": " + e.getMessage());
System.exit(0);
}
}
}
}