Java Code Examples for org.springframework.jdbc.UncategorizedSQLException

Following code examples demonstrate how to use org.springframework.jdbc.UncategorizedSQLExceptionfrom 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.UncategorizedSQLExceptionand various code implementation of this class.

    private boolean isSerious() {
        if (getCause() instanceof UncategorizedSQLException) {
            return false;
        }
        return true;
    } 


    public String getShowMessage() {
        if (getCause() instanceof UncategorizedSQLException) {
            return "数据保存失败,请检查是否存在特殊字符";
        }
        return "数据操作异常,请稍后再试";
    } 

	private static boolean isOraclePackageDiscarded(Exception e) {
		SQLException e1;
		if (e == null)
			return false;

		if (e instanceof SQLException) {
			e1 = (SQLException) e;
			return isDiscardedSQLException(e1);
		}

		if (e instanceof UncategorizedSQLException) {
			e1 = ((UncategorizedSQLException) e).getSQLException();
			return isDiscardedSQLException(e1);
		}
		return false;
	} 

        if (ex instanceof HttpRequestMethodNotSupportedException) {
            return new ModelAndView("jumpMain");
        } else if (ex instanceof UncategorizedSQLException) {
            return new ModelAndView("jumpLogin");
        } else {
            return super.processHandlerException(request, response, handler, ex);
        } 

	public  static String getStackTrace(Throwable t){
		StringWriter sw=new StringWriter();
		PrintWriter pw=new PrintWriter(sw);
		try {
			t.printStackTrace(pw);
			LOG.info(sw.toString());
		}finally{
			pw.close();
		}
		String ms="����ʧ��";
		if(t instanceof UncategorizedSQLException)
			ms="���ܲ������";
		if(t instanceof NumberFormatException){
			ms="�����ʽ����(����������):"+t.getMessage().replaceAll("For input string:", "");
		}
		return ms;
	} 

	public void testCreate() throws Exception {
		try {
			System.out.println("id ====");
		}catch(UncategorizedSQLException e){
			
		System.out.println("sssssssss");
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	} 

    if (e instanceof ServiceStatusException) {
      serviceStatus = ((ServiceStatusException) e).getServiceStatus();
    } else if (e instanceof UncategorizedSQLException) {
      if (e.getMessage().contains("Incorrect string value")) {
        serviceStatus = ServiceStatus.COMMON_ILLEGAL_CHARACTER;
      }
    } 

        if (ex instanceof DataAccessException) {
            throw new IntegrationException(ErrorCode.SYSTEM_ERROR.getValue(), ex);
        } else if (ex instanceof SQLException) {
            throw new IntegrationException(ErrorCode.SYSTEM_ERROR.getValue(), ex);
        } else if (ex instanceof UncategorizedSQLException) {
            throw new IntegrationException(ErrorCode.SYSTEM_ERROR.getValue(), ex);
        } 

        if (e instanceof UnsupportedEncodingException) {
            return Response.clientErr("UnsupportedEncodingExceptiond");
        }else if (e instanceof HttpMessageNotReadableException) {
            return Response.clientErr("Please enter the json parameter");
        }else if (e instanceof NoHandlerFoundException){
            return Response.notFound();
        } 

    public static void main(String[] args) {

        ApplicationContext context = new ClassPathXmlApplicationContext("config.xml");

        AccountDao accountDao = context.getBean("accountDaoImp", AccountDao.class);



        try {

            Account act = accountDao.getOneAccount(6);
            System.out.println("---getOne: " + act);


            accountDao.updateAccount(6, "Meyaa");
    Account act2 = accountDao.getOneAccount(6);
        System.out.println("---getOne: "+act2);

            List<Account> accountList = accountDao.getAllAccounts();
            for (Account account : accountList) {
                System.out.println(account);
            }
        }catch (UncategorizedSQLException uncat){
            System.out.println("Error when update ,but DB can update");
            Account act2 = accountDao.getOneAccount(6);
            System.out.println("---getOne: "+act2);
        }
    } 

	public void testCreate() throws Exception {
		try {
			
	         System.out.println(Integer.toOctalString(9));
			System.out.println(Integer.toHexString(13));
			
		}catch(UncategorizedSQLException e){
			
		System.out.println("sssssssss");
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	} 

    public DataAccessException translate(String task, String sql, SQLException ex) {
        if (task == null) {
            task = "";
        }
        if (sql == null) {
            sql = "";
        }

        log.error("执行SQL语句:" + sql + " 错误!异常如下:", ex);
        return new UncategorizedSQLException(task, sql, ex);
    } 

    public String onUncategorizedSQLException(Exception exception, WebRequest request) {
    	exception.printStackTrace();
    	UncategorizedSQLException u = (UncategorizedSQLException)exception;
        return BaseException.unknowException(HttpStatus.BAD_REQUEST+"",u.getSQLException());
    } 

    public DataAccessException translate(String task, String sql, SQLException e) {
        switch (e.getErrorCode()) {
            case 942:
                return new TableDoesNotExistException("Table does not exist", e);
            case 959:
                return new TablespaceDoesNotExistException("Tablespace does not exist", e);
            case 1918:
                return new UserDoesNotExistException("User does not exist", e);
        }

        return new UncategorizedSQLException("(" + task + "): encountered SQLException [" + e.getMessage() + "]", sql, e);
    } 

Advertisement
Javadoc
Exception thrown when we can't classify a SQLException into one of our generic data access exception

s. @author Rod Johnson @author Juergen Hoeller

Read More
Advertisement