public static Object getBean(String name)
{
if(context == null)
context = WebApplicationContextUtils.getRequiredWebApplicationContext(ServletActionContext.getServletContext());
return context.getBean(name);
}
protected CallableStatement prepareCall(String sql, String jndiName)
throws SQLException
{
log.debug("prepareCall(String sql, String jndiName) start");
long startTime = System.currentTimeMillis();
DataSource ds = (DataSource)SpringContextHolder.getBean(jndiName);
if(ds != null)
throw new RuntimeException("There no dataousrce matching to given jndi name : " + jndiName);
CallableStatement cs = ds.getConnection().prepareCall(sql);
long endTime = System.currentTimeMillis();
if(log.isDebugEnabled())
log.debug("end prepareCall() Execution time: " + (endTime - startTime) + " ms.");
return cs;
}这个是传过去一个调用存储过程的一个方法的样子,,,,
{
if(context == null)
context = WebApplicationContextUtils.getRequiredWebApplicationContext(ServletActionContext.getServletContext());
return context.getBean(name);
}
protected CallableStatement prepareCall(String sql, String jndiName)
throws SQLException
{
log.debug("prepareCall(String sql, String jndiName) start");
long startTime = System.currentTimeMillis();
DataSource ds = (DataSource)SpringContextHolder.getBean(jndiName);
if(ds != null)
throw new RuntimeException("There no dataousrce matching to given jndi name : " + jndiName);
CallableStatement cs = ds.getConnection().prepareCall(sql);
long endTime = System.currentTimeMillis();
if(log.isDebugEnabled())
log.debug("end prepareCall() Execution time: " + (endTime - startTime) + " ms.");
return cs;
}这个是传过去一个调用存储过程的一个方法的样子,,,,
解决方案 »
- 一道算法问题,求解
- 关于java api.。。。。。。。。。。。。
- notify无法唤醒wait的问题
- 有甚麽好的编程网站推介一下?
- 两个中文字符串怎么比较一个是不是另外的子串
- 我是菜鸟,求那位高人帮帮我!!
- 看看这个程序的执行结果是什么?
- 求证:某cell在数据库中的类型为int,用setValueAt((object)new Integer(cellValue).toSting())对吗?
- 学java能向哪些方面发展呀?
- eclipse使用debug调试时,出现Source not found.错误
- 关于String.format问题
- 紧急求助:怎样让JTextField只能输入数字,并且输入指定范围的数字?
public static Object getBean(String name)
{
if(context == null)
context = WebApplicationContextUtils.getRequiredWebApplicationContext(ServletActionContext.getServletContext());
return context.getBean(name);
}
这一段就是取得你在spring中配置的相应的bean,通过方法名也可知,传入的就是要取得的bean名
这与自己新建一个类实现ApplicationContextAware这个接口,并在新建的类中定义一个ApplicationContext
的域一样,当对你的spring配置的所有bean解析完以后,就会自动把你的所有bean的上下文全部注入到这个类里。
protected CallableStatement prepareCall(String sql, String jndiName) throws SQLException {
log.debug("prepareCall(String sql, String jndiName) start");
long startTime = System.currentTimeMillis(); // 获得执行前系统当前毫秒时间
DataSource ds = (DataSource) SpringContextHolder.getBean(jndiName);
// SpringContextHolder
// 应该就是包含你上一段代码的类,因为你的上一个方法是静态的,
// 而jndiName就是你在spring配置文件中建立的bean,从而获得一个数据源 if (ds != null)
throw new RuntimeException("There no dataousrce matching to given jndi name : "
+ jndiName);
CallableStatement cs = ds.getConnection().prepareCall(sql); // 返回一个存储过程的语句
long endTime = System.currentTimeMillis(); // 获得执行后系统当前毫秒时间
if (log.isDebugEnabled())
log.debug("end prepareCall() Execution time: " + (endTime - startTime) + " ms."); // 执行方法的时间
return cs;
}
ApplicationContext就是一个beanFactory,只不过是可配置的,也就是表现形式是个配置文件(ApplicationContext.xml)。
context.getBean(name)根据提供的bean的name创建一个实例
由这句DataSource ds = (DataSource)SpringContextHolder.getBean(jndiName);看,这次创建了一个DataSource 对象ds。
然后使用ds.getConnection().prepareCall(sql);返回一个CallableStatement 对象cs。