Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- /**
- * This class is used to connect to Derby Database.
- */
- public class DatabaseUtility {
- static final String hostName = "jdbc:derby://1527/charitydatabase";
- public static Connection getConnection() {
- Connection connection = null;
- try {
- Class.forName("org.apache.derby.jdbc.ClientDriver");
- connection = DriverManager.getConnection(hostName, "charity", "charity");
- } catch (SQLException | ClassNotFoundException ex) {
- System.out.println(ex.getMessage());
- }
- return connection;
- }
- public static void putConnection(Connection connection) {
- try {
- if(connection != null) {
- connection.close();
- }
- } catch (SQLException ex) {
- System.out.println("Error: " + ex.getMessage());
- } finally {
- if (connection != null) {
- connection = null;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement