package hls.plugin.weixin.qiye;

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

public class DBUtil
{
  private static String oracleDriver;
  private static String url;
  private static String username;
  private static String password;

  static
  {
    try
    {
      get();
      Class.forName(oracleDriver);
    } catch (ClassNotFoundException e) {
      System.out.println("Çý¶¯°ü²»´æÔÚ..");
    }
  }

  public InputStream getPathName(String pathName)
  {
    return DBUtil.class.getClassLoader().getResourceAsStream(pathName);
  }

  private static void get() {
    Properties prop = new Properties();
    InputStream in = null;
    try {
      in = new DBUtil().getPathName("hls/plugin/weixin/qiye/data_jdbc.properties");
      prop.load(in);
      oracleDriver = prop.getProperty("oracleDriver");
      url = prop.getProperty("url");
      username = prop.getProperty("username");
      password = prop.getProperty("password");
    } catch (Exception e) {
      e.printStackTrace();

      if (in != null)
        try {
          in.close();
        } catch (IOException e1) {
          e1.printStackTrace();
        }
    }
    finally
    {
      if (in != null)
        try {
          in.close();
        } catch (IOException e) {
          e.printStackTrace();
        }
    }
  }

  public static Connection getConnection()
    throws SQLException
  {
    return DriverManager.getConnection(url, username, password);
  }

  public static void main(String[] args) {
    try {
      getConnection();
    } catch (SQLException e) {
      e.printStackTrace();
    }
  }
}