您好,欢迎访问代理记账网站
移动应用 微信公众号 联系我们

咨询热线 -

电话 15988168888

联系客服
  • 价格透明
  • 信息保密
  • 进度掌控
  • 售后无忧

DataSource连接失败常见异常捕获

捕获SQLException异常,并对常见的异常进行特殊处理:
private static Boolean sqlTest(DataSource dataSource) {
        try {
            dataSource.setLoginTimeout(5);
            dataSource.getConnection().getClientInfo();
        }catch (SQLException e) {
            if(e.getCause() instanceof CJCommunicationsException){
                //S100
                CJCommunicationsException cjCommunicationsException = (CJCommunicationsException)e.getCause();
                System.out.println("错误码:"+cjCommunicationsException.getSQLState());
                System.out.println("错误信息:"+cjCommunicationsException.getMessage());
            }else if(e.getCause() instanceof CJException){
                //42000,28000
                CJException cjException = (CJException)e.getCause();
                System.out.println("错误码:"+cjException.getSQLState());
                System.out.println("错误信息:"+cjException.getMessage());
            }
            e.printStackTrace();
            return false;
        }
        return true;
    }

S1000

jdbc-url错误

Could not create connection to database server. Attempted reconnect 3 times. Giving up.

42000

数据库名错误

Unknown database 'aaa22'

28000

用户名错误

Access denied for user 'root1'@'10.1.23.90' (using password: YES)

28000

密码错误

Access denied for user 'root'@'10.1.23.90' (using password: YES)


分享:

低价透明

统一报价,无隐形消费

金牌服务

一对一专属顾问7*24小时金牌服务

信息保密

个人信息安全有保障

售后无忧

服务出问题客服经理全程跟进