日期:2014-05-18 浏览次数:20724 次
<named-config name="user">
<property name="driverClass">com.mysql.jdbc.Driver</property>
<property name="jdbcUrl">jdbc:mysql://localhost:3306/</property>
<property name="user">root</property>
<property name="password"></property>
<property name="acquireIncrement">5</property>
<property name="initialPoolSize">10</property>
<property name="minPoolSize">5</property>
<property name="maxPoolSize">20</property>
</named-config>
private static ComboPooledDataSource ds=null;
static
{
ds=new ComboPooledDataSource("user");
}
public static DataSource getDataSource() {
return ds;
}
public static Connection getConnection() throws SQLException
{
return ds.getConnection();
}
public void test_UserDao_impl_find3() throws Exception
{
Connection c1=JdbcUtils.getConnection();
if(c1==null)
{
System.out.println("没拿到!");
}
System.out.println(c1);
}
static
{
ds=new ComboPooledDataSource("user");
}
public static DataSource getDataSource(String username) {
String url="jdbc:mysql://localhost:3306/"+username;
ds.setJdbcUrl(url);
return ds;
}
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/test
jdbc.user=scott
jdbc.password=tiger
#这里使用的是map,不同用户可以取到不同的datasource
private static Map<String,ComboPooledDataSource> dsList=new HashMap<String,ComboPooledDataSource>();