ÔÚ Èý, 14 6Ô 2000 , ÄãдÁË:
> What is your reason for wanting a db connection associated with a particular
> login?
My corparate is going to developing a business system on Linux+Oracle+Tomcat.
There is a lot of vouchers and lists and reports in a account,
and a lot of accounts in a oracle database.
every user open a account must give the oracle username and password.
if i open every account with the "system" username, i must write the dynamic sql:
StringBuffer sql = new StringBuffer();
sql.append( "SELECT * FROM " );
sql.append( username );
sql.append( ".voucher" );
but if i open a account with the particular username, i can write the static sql:
String sql = "SELECT * FROM voucher";
so, i must open a connection with a particular login. :)
>
> ----- Original Message -----
> From: Jian He <[EMAIL PROTECTED]>
> To: Turbine <[EMAIL PROTECTED]>
> Sent: Wednesday, June 14, 2000 12:08 AM
> Subject: DBFactory Patch
>
>
> > Hi
> >
> > when i run DBFactory.getInstance().getConnection(driver, url, user1,
> pass1) to get the first connection,
> > it gives me the right connection.
> > but when i run DBFactory.getInstance().getConnection(driver, url, user2,
> pass2) to get the second connection,
> > it also gives me the first connection, it is not the right connection.
> >
> > so i changed the DBFactory, ConnectionPool, DBConnection classes to solve
> the problem:
> >
> > bash-2.03$ diff old/DBBroker.java DBBroker.java
> > 150c150,153
> > < url = url.trim();
> > ---
> > > StringBuffer key = new StringBuffer();
> > > key.append( url.trim() );
> > > key.append( ':' );
> > > key.append( username.trim() );
> > 152c155
> > < if ( pools.containsKey(url) )
> > ---
> > > if ( pools.containsKey( key ))
> > 154c157
> > < pool = (ConnectionPool) pools.get(url);
> > ---
> > > pool = (ConnectionPool) pools.get( key );
> > 159c162
> > < pools.put( url, pool );
> > ---
> > > pools.put( key, pool );
> > 259c262,263
> > < if (pools.containsKey( url ))
> > ---
> > > String key = url + ":" + connection.getUsername();
> > > if (pools.containsKey( key ))
> > 261c265
> > < ConnectionPool pool = (ConnectionPool)
> ools.get( url );
> > ---
> > > ConnectionPool pool = (ConnectionPool)
> ools.get( key );
> >
> > bash-2.03$ diff old/ConnectionPool.java ConnectionPool.java
> > 175c175
> > < return new DBConnection( db.getConnection(), url );
> > ---
> > > return new DBConnection( db.getConnection(), url, username );
> >
> > bash-2.03$ diff old/DBConnection.java DBConnection.java
> > 77a78,79
> > > /** The username of this connection. */
> > > private String username = "";
> > 86c88
> > < protected DBConnection(Connection connection, String url)
> > ---
> > > protected DBConnection(Connection connection, String url, String
> username)
> > 89a92
> > > this.username = username;
> > 114a118,121
> > > }
> > > public String getUsername()
> > > {
> > > return username;
> >
> >
> > ------------------------------------------------------------
> > To subscribe: [EMAIL PROTECTED]
> > To unsubscribe: [EMAIL PROTECTED]
> > Problems?: [EMAIL PROTECTED]
>
>
>
> ------------------------------------------------------------
> To subscribe: [EMAIL PROTECTED]
> To unsubscribe: [EMAIL PROTECTED]
> Problems?: [EMAIL PROTECTED]
------------------------------------------------------------
To subscribe: [EMAIL PROTECTED]
To unsubscribe: [EMAIL PROTECTED]
Search: <http://www.mail-archive.com/turbine%40list.working-dogs.com/>
Problems?: [EMAIL PROTECTED]