import java.sql.ResultSet;
import java.sql.SQLException;
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.RowMapper;
import org.springframework.jdbc.support.lob.LobHandler;
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");
final LobHandler lobHandler = (LobHandler) ac.getBean("lobHandler");
JdbcTemplate jdbcTemplate= new JdbcTemplate(dataSource);
jdbcTemplate.query("select comments from t_customer where id=?", new Object[] { 2L }, new RowMapper() {
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
return lobHandler.getClobAsString(rs, 1);
}
});
}
}
|