In my application I am using c3p0 for connection pooling. I provide the username and password in the context file.Configuration is below:
<bean id="datasource"
class="com.mchange.v2.c3p0.ComboPooledDataSource" lazy-init="true" destroy-method="close">
<property name="driverClass" value="com.ibm.as400.access.AS400JDBCDriver" />
<property name="jdbcUrl" value="${url}" />
<property name="user" value="${username}" />
<property name="password" value="${password}" /> </bean>
when my application loads then Spring made a connection using this username and password.
Now the problem is if any other user come and login with his profile using directly my login page then i want to replace the Springs connection with the new user’s connection.So the data fetching is done with the new user’s profile my client doesn’t want to change in the properties file.
Pls assist me.
In your scenario, it doesn’t make any sense to have a connection pool since every session will need to open it’s own connection.
You’d be better off opening a connection when a user logs in and then maintaining the same connection in the session scope. Or opening a new connection each time you need it, but that’s an extra overhead you might want to avoid. Just be careful about resource leakage. Since each user that logs in needs their own connection, you’ll need to set session timeouts pretty low to avoid having masses of open connections in abandoned sessions.