Advertisement
Demoralizing_Mrrrgl

JavaDB Problem

Feb 27th, 2013
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.07 KB | None | 0 0
  1.  
  2. import java.sql.Connection;
  3. import java.sql.DriverManager;
  4. import java.sql.SQLException;
  5.  
  6. /**
  7.  * This class is used to connect to Derby Database.
  8.  */
  9. public class DatabaseUtility {
  10.  
  11.         static final String hostName = "jdbc:derby://1527/charitydatabase";
  12.        
  13.     public static Connection getConnection() {
  14.  
  15.         Connection connection = null;
  16.         try {
  17.             Class.forName("org.apache.derby.jdbc.ClientDriver");
  18.             connection = DriverManager.getConnection(hostName, "charity", "charity");
  19.         } catch (SQLException | ClassNotFoundException ex) {
  20.             System.out.println(ex.getMessage());
  21.         }
  22.  
  23.         return connection;
  24.     }
  25.  
  26.     public static void putConnection(Connection connection) {
  27.         try {
  28.             if(connection != null) {
  29.                 connection.close();
  30.             }
  31.         } catch (SQLException ex) {
  32.             System.out.println("Error: " + ex.getMessage());
  33.         } finally {
  34.             if (connection != null) {
  35.                 connection = null;
  36.             }
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement