import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
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.RowCallbackHandler;
class Main {
public static void main(String args[]) throws Exception {
ApplicationContext ac = new ClassPathXmlApplicationContext("context.xml", Main.class);
DataSource dataSource = (DataSource) ac.getBean("dataSource");
// DataSource mysqlDataSource = (DataSource) ac.getBean("mysqlDataSource");
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
jdbcTemplate.query("select first_name from t_customer where last_login < ?",
new Object[] { new java.util.Date() },
new int[] { Types.TIMESTAMP },
new StringExtractingRowCallbackHandler());
}
}
class StringExtractingRowCallbackHandler implements RowCallbackHandler {
public void processRow(ResultSet resultSet) throws SQLException {
while (resultSet.next()) {
System.out.println(resultSet.getString(1));
}
}
}
|