Java Code Examples for org.springframework.jdbc.CannotGetJdbcConnectionException

Following code examples demonstrate how to use org.springframework.jdbc.CannotGetJdbcConnectionExceptionfrom spring-framework. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use org.springframework.jdbc.CannotGetJdbcConnectionExceptionand various code implementation of this class.

	protected void checkDaoConfig() {
		if (this.jdbcTemplate == null) {
			throw new IllegalArgumentException(
					"dataSource or jdbcTemplate is required");
		}
	} 


            if (e instanceof CannotGetJdbcConnectionException) {
                System.out.println("e:......iiiiii." + e.getClass());

            } 

	public void testInitStock(){
		QQStockService stockService = (QQStockService)context.getBean("qqStockService");
		
		try {
			stockService.getRealTimeData();
		} catch (CannotGetJdbcConnectionException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
	} 

	public void handleException(Exception exception, HttpServletRequest request, HttpServletResponse response) {
		logger.error(exception.getMessage(), exception);
		HttpSession httpSession = request.getSession();
		
		if(exception instanceof CannotGetJdbcConnectionException) {
			httpSession.setAttribute("message", "不能获取数据库连接,请联系管理员!");
			response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
		}
		RequestDispatcher rd =  request.getSession().getServletContext().getRequestDispatcher("/error"); 
        try {
			rd.forward(request, response);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
		}
	} 

	public String getMessage() {
		
		if(getCause() instanceof CannotGetJdbcConnectionException){
			return "1";
		}else {
			return "0";
		}	

	} 

    public List<EmployeeDATA> getEmployee(EmployeeDATA employeeDATA) {
        List<EmployeeDATA> employeeDATAList;
        try{
            employeeDATAList = (List<EmployeeDATA>) getJdbcTemplate().queryForObject(
                    "SELECT empl.id, empl.name, empl_and_r.sys_r_id, empl_st.descr FROM empl JOIN empl_and_r ON empl.id = empl_id JOIN empl_st ON empl.st_id = empl_st.id WHERE empl.id = coalesce(?, empl.id) AND empl.name = coalesce(?, empl.name) AND sys_r_id = coalesce(?, sys_r_id) AND empl_st.cond = TRUE;",
                    new Object[]{employeeDATA.getEmployeeId(), employeeDATA.getEmployeeName(), employeeDATA.getSystemRoleId()},
                    new SearchRowMapper()
            );
        }catch (org.springframework.dao.EmptyResultDataAccessException | CannotGetJdbcConnectionException ignored){
            employeeDATAList = null;
        }
        return employeeDATAList;
    } 

Advertisement
Javadoc
Fatal exception thrown when we can't connect to an RDBMS using JDBC. @author Rod Johnson @author Jue

rgen Hoeller

Read More
Advertisement