コード例 #1
0
ファイル: BaseReader.java プロジェクト: hubinix/com.kamike.db
  public T get(T t) {
    GenericSelect<T> select = createSelect(t);

    ResultSet rs = null;
    PreparedStatement ps = null;
    Connection conn = null;

    T entity = null;

    try {
      conn = SysDbInst.getInstance().getDatabase().getSingleConnection();
      ps =
          conn.prepareStatement(
              select.sql(dbName), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
      int index = select.bind(ps);

      rs = ps.executeQuery();
      entity = select.fetchOnce(rs);

    } catch (Exception e) {
      entity = null;
      System.out.println(this.getClass().getName() + e.toString());

    } finally {
      try {
        if (rs != null) {
          rs.close();
          rs = null;
        }
        if (ps != null) {
          ps.close();
          ps = null;
        }
        if (conn != null) {
          conn.close();
          conn = null;
        }
      } catch (SQLException ex) {
        Logger.getLogger(BaseReader.class.getName()).log(Level.SEVERE, null, ex);
      }
    }

    return entity;
  }