예제 #1
0
파일: Jdbc.java 프로젝트: hebun/betting
  public static List<Map<String, String>> select(String sql) {
    if (false == started) start("select not started");
    List<Map<String, String>> list = null;
    try {
      say++;
      if (say % 100 == 0) System.out.print(say + ".");

      ResultSet rs = stmt.executeQuery(sql);
      ResultSetMetaData data = rs.getMetaData();
      int colCount = data.getColumnCount();
      list = new ArrayList<Map<String, String>>();
      while (rs.next()) {

        Hashtable<String, String> hash = new Hashtable<String, String>();
        for (int i = 1; i <= colCount; i++) {

          String value = rs.getString(i) == null ? "NULL" : rs.getString(i);
          hash.put(data.getColumnLabel(i), value);
        }
        list.add(hash);
      }
    } catch (SQLException se) {

      se.printStackTrace();
    } catch (Exception e) {

      e.printStackTrace();
    } finally {

    } // end try
    return list;
  }
예제 #2
0
파일: Jdbc.java 프로젝트: hebun/betting
  public static <T> List<T> select(String sql, Class<T> type) {

    try {
      start("");
      ResultSet rs = stmt.executeQuery(sql);
      ResultSetMetaData metaData = rs.getMetaData();
      int colCount = metaData.getColumnCount();

      String[] columns = new String[colCount];

      for (int i = 0; i < colCount; i++) {
        columns[i] = new String(metaData.getColumnLabel(i + 1));
      }
      List<T> list = new ArrayList<T>();

      while (rs.next()) {
        T obj = type.newInstance();
        for (Field f : type.getDeclaredFields()) {
          if (Modifier.isPrivate(f.getModifiers())) {
            String input = f.getName();
            input = input.substring(0, 1).toUpperCase() + input.substring(1);
            try {
              Class<?> type2 = f.getType();
              // System.out.println(type2);
              if (type2 == Integer.class) {

              } else {
                type2 = String.class;
              }
              Method met = type.getMethod("set" + input, type2);

              if (input.equals("Tarih")) {
                met.invoke(obj, rs.getString(f.getName()));
              }
              met.invoke(obj, rs.getObject(f.getName()));
            } catch (NoSuchMethodException e) {

              e.printStackTrace();
            } catch (Exception e) {
            }
          }
        }
        list.add(obj);
      }
      return list;
    } catch (SQLException se) {
      System.out.println("se in select<T" + sql);
      se.printStackTrace();
      return new ArrayList<T>();
    } catch (Exception e) {
      System.out.println("e in select");
      e.printStackTrace();
      return new ArrayList<T>();
    } finally {
      close("");
    }
  }
예제 #3
0
파일: Jdbc.java 프로젝트: hebun/betting
  public static void query(String sql) {
    if (!started) start("query not started");
    try {
      say++;
      if (say % 100 == 0) System.out.print(say + ".");

      int rs = stmt.executeUpdate(sql);

    } catch (SQLException se) {
      System.out.println(sql);
      se.printStackTrace();
    } catch (Exception e) {

      System.out.println("query ex");
    } finally {

    } // end try
  }
예제 #4
0
파일: Jdbc.java 프로젝트: hebun/betting
  public static List<Match> selectMatch(String string) {
    if (false == started) start("selectMatch not started");
    List<Match> list = null;
    try {
      say++;
      if (say % 100 == 0) System.out.print(say + ".");

      ResultSet rs = stmt.executeQuery(string);
      ResultSetMetaData data = rs.getMetaData();
      int colCount = data.getColumnCount();
      list = new ArrayList<Match>();
      while (rs.next()) {

        Match match =
            new Match(
                rs.getInt("siteId"),
                rs.getString("externId"),
                rs.getString("homeTeam"),
                rs.getString("awayTeam"),
                rs.getInt("ht"),
                rs.getInt("at"),
                rs.getInt("draw"),
                rs.getInt("deht"),
                rs.getInt("deat"),
                rs.getString("tarih"));

        list.add(match);
      }
    } catch (SQLException se) {

      se.printStackTrace();
    } catch (Exception e) {

      e.printStackTrace();
    } finally {

    } // end try
    return list;
  }