Package org.springframework.jdbc.core

Examples of org.springframework.jdbc.core.RowCallbackHandler


            return conn.prepareStatement(sql,
                ResultSet.TYPE_FORWARD_ONLY,
                ResultSet.CONCUR_READ_ONLY);
          }

        }, new RowCallbackHandler() {

          @Override
          public void processRow(ResultSet rs) throws SQLException {
            int instanceId = rs.getInt(1);
            String word = rs.getString(2);
View Full Code Here


    PreparedStatement s = null;
    Connection conn = null;
    ResultSet rs = null;
    try {
      // jdbcTemplate.query(strQuery, new RowCallbackHandler() {
      RowCallbackHandler ch = new RowCallbackHandler() {

        @Override
        public void processRow(ResultSet rs) throws SQLException {
          String label = "";
          int run = 0;
          int fold = 0;
          boolean train = true;
          long instanceId = rs.getLong(1);
          String className = rs.getString(2);
          if (rs.getMetaData().getColumnCount() >= 3)
            train = rs.getBoolean(3);
          if (rs.getMetaData().getColumnCount() >= 4) {
            label = rs.getString(4);
            if (label == null)
              label = "";
          }
          if (rs.getMetaData().getColumnCount() >= 5)
            fold = rs.getInt(5);
          if (rs.getMetaData().getColumnCount() >= 6)
            run = rs.getInt(6);
          // get runs for label
          SortedMap<Integer, SortedMap<Integer, SortedMap<Boolean, SortedMap<Long, String>>>> runToInstanceMap = instanceLabel
              .getLabelToInstanceMap().get(label);
          if (runToInstanceMap == null) {
            runToInstanceMap = new TreeMap<Integer, SortedMap<Integer, SortedMap<Boolean, SortedMap<Long, String>>>>();
            instanceLabel.getLabelToInstanceMap().put(label,
                runToInstanceMap);
          }
          // get folds for run
          SortedMap<Integer, SortedMap<Boolean, SortedMap<Long, String>>> foldToInstanceMap = runToInstanceMap
              .get(run);
          if (foldToInstanceMap == null) {
            foldToInstanceMap = new TreeMap<Integer, SortedMap<Boolean, SortedMap<Long, String>>>();
            runToInstanceMap.put(run, foldToInstanceMap);
          }
          // get train/test set for fold
          SortedMap<Boolean, SortedMap<Long, String>> ttToClassMap = foldToInstanceMap
              .get(fold);
          if (ttToClassMap == null) {
            ttToClassMap = new TreeMap<Boolean, SortedMap<Long, String>>();
            foldToInstanceMap.put(fold, ttToClassMap);
          }
          // get instances for train/test set
          SortedMap<Long, String> instanceToClassMap = ttToClassMap
              .get(train);
          if (instanceToClassMap == null) {
            instanceToClassMap = new TreeMap<Long, String>();
            ttToClassMap.put(train, instanceToClassMap);
          }
          // set the instance class
          instanceToClassMap.put(instanceId, className);
          // add the class to the labelToClassMap
          SortedSet<String> labelClasses = instanceLabel
              .getLabelToClassMap().get(label);
          if (labelClasses == null) {
            labelClasses = new TreeSet<String>();
            instanceLabel.getLabelToClassMap().put(label,
                labelClasses);
          }
          if (!labelClasses.contains(className))
            labelClasses.add(className);
        }
      };
      conn = this.jdbcTemplate.getDataSource().getConnection();
      s = conn.prepareStatement(strQuery,
          java.sql.ResultSet.TYPE_FORWARD_ONLY,
          java.sql.ResultSet.CONCUR_READ_ONLY);
      if ("MySQL".equals(conn.getMetaData().getDatabaseProductName())) {
        s.setFetchSize(Integer.MIN_VALUE);
      } else if (s.getClass().getName()
          .equals("com.microsoft.sqlserver.jdbc.SQLServerStatement")) {
        try {
          BeanUtils.setProperty(s, "responseBuffering", "adaptive");
        } catch (IllegalAccessException e) {
          log.warn("error setting responseBuffering", e);
        } catch (InvocationTargetException e) {
          log.warn("error setting responseBuffering", e);
        }
      }
      rs = s.executeQuery();
      while (rs.next()) {
        ch.processRow(rs);
      }
    } catch (SQLException j) {
      log.error("loadInstances failed", j);
      throw new RuntimeException(j);
    } finally {
View Full Code Here

  private void initializeInstanceIndices(String instanceClassQuery,
      final Map<Long, String> instanceIDClassLabel,
      final Map<Long, Integer> instanceToIndexMap) {
    // read in all instance ids
    jdbcTemplate.query(instanceClassQuery, new RowCallbackHandler() {
      @Override
      public void processRow(ResultSet rs) throws SQLException {
        instanceIDClassLabel.put(rs.getLong(1), rs.getString(2));
      }
    });
View Full Code Here

  @Override
  public void updateData() {
    String sql = "SELECT * FROM "+quoteTable("weight_class")+" wc LEFT JOIN "+quoteTable("weight_class_description")+
      " wcd ON (wc.weight_class_id = wcd.weight_class_id)";
    final Map<String, WeightClass> dataMap = new HashMap<String, WeightClass>();
    getJdbcOperations().query(sql, new RowCallbackHandler(){
      @Override
      public void processRow(ResultSet rs) throws SQLException {
        WeightClass lc = new WeightClass();
        lc.setId(rs.getInt("weight_class_id"));
        lc.setTitle(rs.getString("title"));
View Full Code Here

  @Override
  public void updateData() {
    String sql = "SELECT * FROM "+quoteTable("length_class")+" mc LEFT JOIN "+quoteTable("length_class_description")+
      " mcd ON (mc.length_class_id = mcd.length_class_id)";
    final Map<String, LengthClass> dataMap = new HashMap<String, LengthClass>();
    getJdbcOperations().query(sql, new RowCallbackHandler(){
      @Override
      public void processRow(ResultSet rs) throws SQLException {
        LengthClass lc = new LengthClass();
        lc.setId(rs.getInt("length_class_id"));
        lc.setTitle(rs.getString("title"));
View Full Code Here

    final long whenDiff = getEnvironment().getProperty(
        "currency.update.whenDiff", Long.class);
    final boolean willUpdate[] = new boolean[]{false};
    String sql = "SELECT * FROM "+quoteTable("currency")+" WHERE status=?";
    final Map<String, Currency> dataMap = new HashMap<String, Currency>();
    getJdbcOperations().query(sql, new Object[]{Status.ENABLED}, new RowCallbackHandler(){
     
      @Override
      public void processRow(ResultSet rs) throws SQLException {
        Currency currency = new Currency();
        currency.setId(rs.getInt("currency_id"));
View Full Code Here

    dataMap.put(0, http);
    dataMap.put(0, https);
   
    String sql = "SELECT store_id, url FROM "+quoteTable("store");
   
    getJdbcOperations().query(sql, new RowCallbackHandler(){
      @Override
      public void processRow(ResultSet rs) throws SQLException {
        Integer storeId = rs.getInt("store_id");
        String url = rs.getString("url");
        int pos = url.indexOf("://");
View Full Code Here

    this.txTemplate.execute(new TransactionCallback<Object>() {

      @Override
      public Object doInTransaction(TransactionStatus arg0) {
        namedJdbcTemplate.query(queryGetDocument, idQuery,
            new RowCallbackHandler() {
              boolean bFirstRowRead = false;

              @Override
              public void processRow(ResultSet rs)
                  throws SQLException {
View Full Code Here

      }
      if (log.isInfoEnabled())
        log.info("createConceptGraph(): file not found, creating concept graph from database.");
      final ConceptGraph cg = new ConceptGraph();
      final Set<String> roots = new HashSet<String>();
      this.jdbcTemplate.query(query, new RowCallbackHandler() {
        int nRowsProcessed = 0;

        @Override
        public void processRow(ResultSet rs) throws SQLException {
          String child = rs.getString(1);
View Full Code Here

   */
  public static String getBlob(String id, String tableName, final String columnName, JdbcTemplate jdbcTemplate) {
    String ls_sql = "select " + columnName + " from " + tableName + " where id='" + id + "'";

    // 查询并获得输入流
    jdbcTemplate.query(ls_sql, new RowCallbackHandler() {
     
      public void processRow(ResultSet rs) throws SQLException {
        inStream = rs.getBinaryStream(columnName);
      }
    });
View Full Code Here

TOP

Related Classes of org.springframework.jdbc.core.RowCallbackHandler

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.