lcjing commented on issue #31618:
URL:
https://github.com/apache/shardingsphere/issues/31618#issuecomment-2159696039
* You don't seem to understand what I mean, it's not because of the issue
with driver `p6spy`, it may be due to connection pooling. The connection pool
used in my project is `org.apache.tomcat.jdbc.pool.DataSource`, The root cause
is that when setting a property in the `DataSourcePoolReflection `class, the
`driverClassName` property will be skipped, resulting in an invalid
`driverClassName` configured in yaml. Subsequently, A NullPointerException
occurred when creating a connection in
`org.apache.tomcat.jdbc.pool.PooledConnection`, as follows:
```java
protected void connectUsingDriver() throws SQLException {
try {
if (driver==null) {
if (log.isDebugEnabled()) {
log.debug("Instantiating driver using class:
"+poolProperties.getDriverClassName()+" [url="+poolProperties.getUrl()+"]");
}
driver = (java.sql.Driver)
Class.forName(poolProperties.getDriverClassName(),
true,
PooledConnection.class.getClassLoader()
).newInstance();
}
} catch (java.lang.Exception cn) {
if (log.isDebugEnabled()) {
log.debug("Unable to instantiate JDBC driver.", cn);
}
SQLException ex = new SQLException(cn.getMessage());
ex.initCause(cn);
throw ex;
}
......
}
```
* I don't know why ShardingJDBC configured to ignore the `driverClassName`
property when setting properties:
```java
SKIPPED_PROPERTY_KEYS = new HashSet<>(Arrays.asList("loginTimeout",
"driverClassName"));
```
* my yaml configuration is `sharding-master-datasource.yaml`
```yaml
dataSources:
db_test:
dataSourceClassName: org.apache.tomcat.jdbc.pool.DataSource
driverClassName: com.mysql.jdbc.Driver
url:
jdbc:mysql://localhost:3306?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8
username: u_dev
password: 123456
rules:
- !SHARDING
tables:
t_user_log:
actualDataNodes: db_user.t_user_log_$->{2024..2030}
tableStrategy:
complex:
shardingColumns: create_time, user_log_no
shardingAlgorithmName: user-log-complex
shardingAlgorithms:
user-log-complex:
type: complex
props:
algorithm-class-name:
com.user.sharding.algorithm.UserLogShardingAlgorithm
- !SINGLE
tables:
- "*.*" # 加载全部单表
props:
spl-show: true
check:
table:
metadata:
enabled: false
```
* spring configuration
```xml
<bean id="shardingDataSourceMaster"
class="org.springframework.jdbc.datasource.SimpleDriverDataSource">
<property name="driverClass"
value="org.apache.shardingsphere.driver.ShardingSphereDriver" />
<property name="url"
value="jdbc:shardingsphere:classpath:sharding-master-datasource.yaml" />
</bean>
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]