Package net.kirke.mp3dj

Source Code of net.kirke.mp3dj.ConnectionHelper

package net.kirke.mp3dj;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import net.kirke.mp3dj.resources.Msgs;

public class ConnectionHelper {
  private static ConnectionHelper instance;
  private Msgs msgs;
  private String url;

  private ConnectionHelper() {
    msgs = new Msgs();
    String driver = "org.hsqldb.jdbcDriver";

    try {
      Class.forName(driver);
      url = "jdbc:hsqldb:file:mp3db/mp3db";
    } catch (Exception x) {
      Object params[] = { driver, x.getMessage() };
      String msg = msgs.getMessage("UNABLE_TO_LOAD_DRIVER", params);
      System.out.println("ConnectionHelper:  " + msg);
      x.printStackTrace();
    }
  }
 
  public static void close(Connection connection) {
    try {
      if (connection != null) {
        connection.close();
      }
    } catch (SQLException x) {
      System.out.println("close:  " + x.getMessage());
      x.printStackTrace();
    }
  }

  public static Connection getConnection() throws SQLException {
    if (instance == null) {
      instance = new ConnectionHelper();
    }
    try {
      return DriverManager.getConnection(instance.url);
    } catch (SQLException x) {
      System.out.println("getConnection:  " + x.getMessage());
      throw x;
    }
  }

  public static String getUrl() {
    if (instance == null) {
      instance = new ConnectionHelper();
    }
    return instance.url;
  }
}
TOP

Related Classes of net.kirke.mp3dj.ConnectionHelper

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.