Package org.springframework.jdbc.support.rowset

Examples of org.springframework.jdbc.support.rowset.SqlRowSetMetaData


      SqlRowSet sqlRowSet = null;
      String ls_id = "";
      for (int j = 0; j < listSQL.size(); j++) {
        String sql = String.valueOf(listSQL.get(j)); // 逐条获取sql语句
        sqlRowSet = jdbcTemplate.queryForRowSet(sql);
        SqlRowSetMetaData sqlRsmd = sqlRowSet.getMetaData();
        int columnCount = sqlRsmd.getColumnCount(); // 获得表字段个数
        String tableName = sqlRsmd.getTableName(columnCount); // 获得表名称
        if(StringUtils.isEmpty(tableName)){
          tableName = PublicUtil.getTableName(sql);
        }
        String tableId="";
        while (sqlRowSet.next()) {
          StringBuffer ColumnName = new StringBuffer();
          StringBuffer ColumnValue = new StringBuffer();

          for (int i = 1; i <= columnCount; i++) {
            String value = sqlRowSet.getString(i);
            if (value == null || "".equals(value)) {
              value = "";
            }
            Map<String, String> fieldMap = new HashMap<String, String>();
            fieldMap.put("name", sqlRsmd.getColumnName(i));
            fieldMap.put("fieldType", String.valueOf(sqlRsmd.getColumnType(i)));
            // 生成插入数据sql语句
            if (i == 1) {
              // 先生成删除指定ID语句,清除现有冲突数据
              insertList.add("delete from " + tableName + " where " + sqlRsmd.getColumnName(i) + "='" + value + "';");

              ColumnName.append(sqlRsmd.getColumnName(i));
              ls_id = value;
              tableId = value;
              if (Types.CHAR == sqlRsmd.getColumnType(i) || Types.VARCHAR == sqlRsmd.getColumnType(i)) {
                ColumnValue.append("'").append(value).append("',");
              } else if (Types.SMALLINT == sqlRsmd.getColumnType(i) || Types.INTEGER == sqlRsmd.getColumnType(i) || Types.BIGINT == sqlRsmd.getColumnType(i) || Types.FLOAT == sqlRsmd.getColumnType(i) || Types.DOUBLE == sqlRsmd.getColumnType(i) || Types.NUMERIC == sqlRsmd.getColumnType(i) || Types.DECIMAL == sqlRsmd.getColumnType(i)) {
                if ("".equals(value))  value = "0";
                ColumnValue.append(value).append(",");
              } else if (Types.DATE == sqlRsmd.getColumnType(i) || Types.TIME == sqlRsmd.getColumnType(i) || Types.TIMESTAMP == sqlRsmd.getColumnType(i)) {
                if ("".equals(value))
                  value = "2000-01-01";
                ColumnValue.append("'").append(value).append("',");
              } else {
                ColumnValue.append(value).append(",");
              }
            } else if (i == columnCount) {
              ColumnName.append("," + sqlRsmd.getColumnName(i));
              if (Types.CHAR == sqlRsmd.getColumnType(i) || Types.VARCHAR == sqlRsmd.getColumnType(i) || Types.LONGVARCHAR == sqlRsmd.getColumnType(i)) {
                ColumnValue.append("'").append(value).append("'");
              } else if (Types.SMALLINT == sqlRsmd.getColumnType(i) || Types.INTEGER == sqlRsmd.getColumnType(i) || Types.BIGINT == sqlRsmd.getColumnType(i) || Types.FLOAT == sqlRsmd.getColumnType(i) || Types.DOUBLE == sqlRsmd.getColumnType(i) || Types.NUMERIC == sqlRsmd.getColumnType(i) || Types.DECIMAL == sqlRsmd.getColumnType(i)) {
                if ("".equals(value))  value = "0";
                ColumnValue.append(value);
              } else if (Types.DATE == sqlRsmd.getColumnType(i) || Types.TIME == sqlRsmd.getColumnType(i) || Types.TIMESTAMP == sqlRsmd.getColumnType(i)) {
                if ("".equals(value))
                  value = "2000-01-01";
                ColumnValue.append("'").append(value).append("'");
              } else {
                ColumnValue.append(value).append("");
              }
            } else {
              ColumnName.append("," + sqlRsmd.getColumnName(i));
              if (Types.CHAR == sqlRsmd.getColumnType(i) || Types.VARCHAR == sqlRsmd.getColumnType(i) || Types.LONGVARCHAR == sqlRsmd.getColumnType(i)) {
                ColumnValue.append("'").append(value).append("'").append(",");
              } else if (Types.SMALLINT == sqlRsmd.getColumnType(i) || Types.INTEGER == sqlRsmd.getColumnType(i) || Types.BIGINT == sqlRsmd.getColumnType(i) || Types.FLOAT == sqlRsmd.getColumnType(i) || Types.DOUBLE == sqlRsmd.getColumnType(i) || Types.NUMERIC == sqlRsmd.getColumnType(i) || Types.DECIMAL == sqlRsmd.getColumnType(i)) {
                if ("".equals(value))  value = "0";
                ColumnValue.append(value).append(",");
              } else if (Types.DATE == sqlRsmd.getColumnType(i) || Types.TIME == sqlRsmd.getColumnType(i) || Types.TIMESTAMP == sqlRsmd.getColumnType(i)) {
                if ("".equals(value))
                  value = "2000-01-01";
                ColumnValue.append("'").append(value).append("',");
              } else if (Types.BLOB == sqlRsmd.getColumnType(i) || Types.LONGVARCHAR == sqlRsmd.getColumnType(i) || Types.LONGNVARCHAR == sqlRsmd.getColumnType(i) || Types.BINARY == sqlRsmd.getColumnType(i) || Types.LONGVARBINARY == sqlRsmd.getColumnType(i) || Types.VARBINARY == sqlRsmd.getColumnType(i)) {
                String ls_tmp = getBlob(ls_id, tableName, sqlRsmd.getColumnName(i), jdbcTemplate);
                ColumnValue.append(ls_tmp).append(",");
              } else {
                ColumnValue.append(value).append(",");
              }
            }
View Full Code Here


    this.removePrefix = removePrefix;
    return this;
  }

  public Map<String, Object> mapRow(SqlRowSet rs, int rowNum) {
    SqlRowSetMetaData rsmd = rs.getMetaData();
    int columnCount = rsmd.getColumnCount();
    Map<String, Object> mapOfColValues = new HashMap<String, Object>(
        columnCount);
    for (int i = 1; i <= columnCount; i++) {
      String key = rsmd.getColumnName(i);
      if (removePrefix != null) {
        key = key.replaceFirst(removePrefix, "");
      }
      Object obj = getColumnValue(rs, i);
      if (obj instanceof String) {
View Full Code Here

        final SqlRowSet rs = this.jdbcTemplate.queryForRowSet(sql);

        final List<ResultsetRowData> resultsetDataRows = new ArrayList<>();

        final SqlRowSetMetaData rsmd = rs.getMetaData();

        while (rs.next()) {
            final List<String> columnValues = new ArrayList<>();
            for (int i = 0; i < rsmd.getColumnCount(); i++) {
                final String columnName = rsmd.getColumnName(i + 1);
                final String columnValue = rs.getString(columnName);
                columnValues.add(columnValue);
            }

            final ResultsetRowData resultsetDataRow = ResultsetRowData.create(columnValues);
View Full Code Here

        final SqlRowSet rs = this.jdbcTemplate.queryForRowSet(sql);

        final List<ResultsetColumnHeaderData> columnHeaders = new ArrayList<>();
        final List<ResultsetRowData> resultsetDataRows = new ArrayList<>();

        final SqlRowSetMetaData rsmd = rs.getMetaData();

        for (int i = 0; i < rsmd.getColumnCount(); i++) {

            final String columnName = rsmd.getColumnName(i + 1);
            final String columnType = rsmd.getColumnTypeName(i + 1);

            final ResultsetColumnHeaderData columnHeader = ResultsetColumnHeaderData.basic(columnName, columnType);
            columnHeaders.add(columnHeader);
        }

        while (rs.next()) {
            final List<String> columnValues = new ArrayList<>();
            for (int i = 0; i < rsmd.getColumnCount(); i++) {
                final String columnName = rsmd.getColumnName(i + 1);
                final String columnValue = rs.getString(columnName);
                columnValues.add(columnValue);
            }

            final ResultsetRowData resultsetDataRow = ResultsetRowData.create(columnValues);
View Full Code Here

TOP

Related Classes of org.springframework.jdbc.support.rowset.SqlRowSetMetaData

Copyright © 2018 www.massapicom. 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.