Skip to content

Commit 6ec43a8

Browse files
author
高阳
committed
Merge branch 'master' of https://github.com/alibaba/druid
2 parents 27ee6dd + 34d07a9 commit 6ec43a8

File tree

2 files changed

+60
-2
lines changed

2 files changed

+60
-2
lines changed

src/main/java/com/alibaba/druid/pool/DruidDataSource.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
import com.alibaba.druid.filter.FilterChainImpl;
5555
import com.alibaba.druid.mock.MockDriver;
5656
import com.alibaba.druid.pool.DruidPooledPreparedStatement.PreparedStatementKey;
57+
import com.alibaba.druid.pool.vendor.DB2ExceptionSorter;
5758
import com.alibaba.druid.pool.vendor.InformixExceptionSorter;
5859
import com.alibaba.druid.pool.vendor.MSSQLValidConnectionChecker;
5960
import com.alibaba.druid.pool.vendor.MockExceptionSorter;
@@ -853,9 +854,9 @@ private void initValidConnectionChecker() {
853854

854855
private void initExceptionSorter() {
855856
String realDriverClassName = driver.getClass().getName();
856-
if (realDriverClassName.equals("com.mysql.jdbc.Driver")) {
857+
if (realDriverClassName.equals(JdbcConstants.MYSQL_DRIVER)) {
857858
this.exceptionSorter = new MySqlExceptionSorter();
858-
} else if (realDriverClassName.equals("oracle.jdbc.driver.OracleDriver")) {
859+
} else if (realDriverClassName.equals(JdbcConstants.ORACLE_DRIVER)) {
859860
this.exceptionSorter = new OracleExceptionSorter();
860861
} else if (realDriverClassName.equals("com.informix.jdbc.IfxDriver")) {
861862
this.exceptionSorter = new InformixExceptionSorter();
@@ -865,6 +866,8 @@ private void initExceptionSorter() {
865866

866867
} else if (realDriverClassName.equals("com.alibaba.druid.mock.MockDriver")) {
867868
this.exceptionSorter = new MockExceptionSorter();
869+
} else if (realDriverClassName.contains("DB2")) {
870+
this.exceptionSorter = new DB2ExceptionSorter();
868871
}
869872
}
870873

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright 1999-2011 Alibaba Group Holding Ltd.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.alibaba.druid.pool.vendor;
17+
18+
import java.sql.SQLException;
19+
import java.util.Properties;
20+
21+
import com.alibaba.druid.pool.ExceptionSorter;
22+
23+
public class DB2ExceptionSorter implements ExceptionSorter {
24+
25+
@Override
26+
public boolean isExceptionFatal(SQLException e) {
27+
String sqlState = e.getSQLState();
28+
if (sqlState != null && sqlState.startsWith("08")) { // Connection Exception
29+
return true;
30+
}
31+
32+
int errorCode = e.getErrorCode();
33+
switch (errorCode) {
34+
case -512: // STATEMENT REFERENCE TO REMOTE OBJECT IS INVALID
35+
case -514: // THE CURSOR IS NOT IN A PREPARED STATE
36+
case -516: // THE DESCRIBE STATEMENT DOES NOT SPECIFY A PREPARED STATEMENT
37+
case -518: // THE EXECUTE STATEMENT DOES NOT IDENTIFY A VALID PREPARED STATEMENT
38+
case -525: // THE SQL STATEMENT CANNOT BE EXECUTED BECAUSE IT WAS IN ERROR AT BIND TIME FOR SECTION = sectno
39+
// PACKAGE = pkgname CONSISTENCY TOKEN = contoken
40+
case -909: // THE OBJECT HAS BEEN DELETED OR ALTERED
41+
case -918: // THE SQL STATEMENT CANNOT BE EXECUTED BECAUSE A CONNECTION HAS BEEN LOST
42+
case -924: // DB2 CONNECTION INTERNAL ERROR, function-code,return-code,reason-code
43+
return true;
44+
default:
45+
break;
46+
}
47+
return false;
48+
}
49+
50+
@Override
51+
public void configFromProperties(Properties properties) {
52+
53+
}
54+
55+
}

0 commit comments

Comments
 (0)