Java 无法将数据源转换为com.mchange.v2.c3p0.PooledDataSource
我正在尝试使用以下代码创建context.xml:Java 无法将数据源转换为com.mchange.v2.c3p0.PooledDataSource,java,jdbc,Java,Jdbc,我正在尝试使用以下代码创建context.xml: ComboPooledDataSource cpds = new ComboPooledDataSource(); try { cpds.setDriverClass( "net.sourceforge.jtds.jdbc.Driver" ); //loads the jdbc driver cpds.setJdbcUrl( "jdbc:jtds:sqlserver://10.38.28
ComboPooledDataSource cpds = new ComboPooledDataSource();
try {
cpds.setDriverClass( "net.sourceforge.jtds.jdbc.Driver" ); //loads the jdbc driver
cpds.setJdbcUrl( "jdbc:jtds:sqlserver://10.38.28.77/MyDB" );
cpds.setUser("sa");
cpds.setPassword("password");
cpds.setMaxStatements( 180 );
} catch (PropertyVetoException e) {
e.printStackTrace();
}
return cpds.getConnection();
我的意思是,将此硬编码设置转换为context.xml,如:
<Resource name="jdbc/MyDBHrd"
driverClass="net.sourceforge.jtds.jdbc.Driver"
maxPoolSize="100"
minPoolSize="15"
acquireIncrement="1"
auth="Container"
maxStatements="50"
idleConnectionTestPeriod="3600"
testConnectionOnCheckin="true"
automaticTestTable="connection_test"
maxIdleTime="21600"
factory="org.apache.naming.factory.BeanFactory"
type="com.mchange.v2.c3p0.ComboPooledDataSource"
jdbcUrl="jdbc:jtds:sqlserver://192.168.114.130/MyDB"
user="sa" password="password" />
抛出:
ClassCastException: org.apache.tomcat.dbcp.dbcp.DataSource cannot be cast to com.mchange.v2.c3p0.PooledDataSource
您应该将数据源声明为普通类型,而不是组合类型。您要求Tomcat制作一个数据源,但它不会为您制作其中一个。如果您需要将普通数据源封装在其中一个中,请使用Java进行封装
ClassCastException: org.apache.tomcat.dbcp.dbcp.DataSource cannot be cast to com.mchange.v2.c3p0.PooledDataSource