tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 
 Spring > JDBC > Row Count Callback Handler

Row Count Callback Handler 

Spring JDBC Framework simplifies the use of JDBC and helps to avoid common errors. The following example shows using RowCountCallbackHandler class which is an implementation of RowCallbackHandler interface.


File Name  :  
/SpringJDBC001/conf/basic/applicationContext.xml 

File Name  :  
com/bethecoder/tutorials/spring3/tests/RowCountCallbackHandlerTest.java 
Author  :  Sudhakar KV
Email  :  kvenkatasudhakar@gmail.com
   
package com.bethecoder.tutorials.spring3.tests;

import java.util.Arrays;

import javax.sql.DataSource;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowCountCallbackHandler;

public class RowCountCallbackHandlerTest {

  /**
   @param args
   */
  public static void main(String[] args) {
    
    /**
     * Initialize context and get the JdbcTemplate
     */
    ApplicationContext appContext = new ClassPathXmlApplicationContext("applicationContext.xml");
    DataSource dataSource = (DataSourceappContext.getBean("dataSource");
    JdbcTemplate template = new JdbcTemplate(dataSource);

    RowCountCallbackHandler handler = new RowCountCallbackHandler();
    template.query("select * from USER", handler);
    System.out.println("Row count : " + handler.getRowCount());
    System.out.println("Column Names : " + Arrays.toString(handler.getColumnNames()));
  }

}
   

It gives the following output,
Row count : 5
Column Names : [ID, NAME, AGE, SALARY]


                    Print

   



Books Recommendation

 
 
bl  br