You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Henri Yandell <fl...@gmail.com> on 2005/08/03 19:35:42 UTC

[dbutils] SystemDataSource

Just had need to hack together a simple DataSource class and wondered
if it would fit nicely in dbutils. Name is either SystemDataSource
(after SystemClassLoader) or DriverManagerDataSource, it uses Java -D
properties and the DriverManager, so is very lightweight and something
nice to start with before moving up to a container that supplies a
real DataSource.

I imagine there are MockDataSources out there that are similar too for
unit testing, but nothing in DbUtils yet.

(code follows, it's pretty dumb)

public class SystemDataSource implements DataSource {

    private String driver = System.getProperty("jdbc.driver");
    private String username = System.getProperty("jdbc.user");
    private String password = System.getProperty("jdbc.password");
    private String uri = System.getProperty("jdbc.uri");

    public SystemDataSource() {
        DbUtils.loadDriver(driver);
    }

    public Connection getConnection() throws SQLException {
        return DriverManager.getConnection(this.uri, this.username,
this.password);
    }

    public Connection getConnection(String username, String password)
throws SQLException {
        return DriverManager.getConnection(this.uri, username, password);
    }

    public PrintWriter getLogWriter() throws SQLException {
        return DriverManager.getLogWriter();
    }

    public void setLogWriter(PrintWriter logWriter) throws SQLException {
        DriverManager.setLogWriter(logWriter);
    }

    public void setLoginTimeout(int timeout) throws SQLException {
        DriverManager.setLoginTimeout(timeout);
    }

    public int getLoginTimeout() throws SQLException {
        return DriverManager.getLoginTimeout();
    }

}

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Re: [dbutils] SystemDataSource

Posted by David Graham <gr...@yahoo.com>.
For some reason the website is distributed with the C3P0 download.  It
contains great docs on how to setup the parameters.  I've been using it in
production with Hibernate for over a year and it works great.

David

--- Henri Yandell <fl...@gmail.com> wrote:

> On 8/4/05, David Graham <gr...@yahoo.com> wrote:
> > Why not just use a real DataSource from C3P0 or Proxool?  They're
> fully
> > featured and easy to setup.  
> 
> DbUtils was already in the classpath :)
> 
> They'd be getting replaced by the target containers DataSource, I just
> needed something to get the code deployed before the target container
> has been chosen.
> 
> > Also, we should not use properties named
> > jdbc.* as they are potentially used by drivers.
> 
> Thanks, will change that.
> 
> > 
> > http://sourceforge.net/projects/c3p0
> 
> No real website :)
> 
> > http://proxool.sourceforge.net/
> 
> Now this I like. You're right that I should be doing the slightly more
> work of hooking this up (previously it would have been poolman or
> simple-jndi) instead of my proposed simple dbutils approach.
> 
> Hen
> 


Get Firefox!
http://www.mozilla.org/firefox/


		
____________________________________________________
Start your day with Yahoo! - make it your home page 
http://www.yahoo.com/r/hs 
 

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Re: [dbutils] SystemDataSource

Posted by Henri Yandell <fl...@gmail.com>.
On 8/4/05, David Graham <gr...@yahoo.com> wrote:
> Why not just use a real DataSource from C3P0 or Proxool?  They're fully
> featured and easy to setup.  

DbUtils was already in the classpath :)

They'd be getting replaced by the target containers DataSource, I just
needed something to get the code deployed before the target container
has been chosen.

> Also, we should not use properties named
> jdbc.* as they are potentially used by drivers.

Thanks, will change that.

> 
> http://sourceforge.net/projects/c3p0

No real website :)

> http://proxool.sourceforge.net/

Now this I like. You're right that I should be doing the slightly more
work of hooking this up (previously it would have been poolman or
simple-jndi) instead of my proposed simple dbutils approach.

Hen

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Re: [dbutils] SystemDataSource

Posted by John McNally <jm...@collab.net>.
Both of these suggestions are connection pooling datasources; or do they 
also provide a simple datasource? Jakarta Commons already has DBCP which 
offers a couple connection pooling datasources, no need to go looking to 
sourceforge.

John McNally

David Graham wrote:

>Why not just use a real DataSource from C3P0 or Proxool?  They're fully
>featured and easy to setup.  Also, we should not use properties named
>jdbc.* as they are potentially used by drivers.
>
>http://sourceforge.net/projects/c3p0
>http://proxool.sourceforge.net/
>
>David
>
>--- Henri Yandell <fl...@gmail.com> wrote:
>
>  
>
>>Just had need to hack together a simple DataSource class and wondered
>>if it would fit nicely in dbutils. Name is either SystemDataSource
>>(after SystemClassLoader) or DriverManagerDataSource, it uses Java -D
>>properties and the DriverManager, so is very lightweight and something
>>nice to start with before moving up to a container that supplies a
>>real DataSource.
>>
>>I imagine there are MockDataSources out there that are similar too for
>>unit testing, but nothing in DbUtils yet.
>>
>>(code follows, it's pretty dumb)
>>
>>public class SystemDataSource implements DataSource {
>>
>>    private String driver = System.getProperty("jdbc.driver");
>>    private String username = System.getProperty("jdbc.user");
>>    private String password = System.getProperty("jdbc.password");
>>    private String uri = System.getProperty("jdbc.uri");
>>
>>    public SystemDataSource() {
>>        DbUtils.loadDriver(driver);
>>    }
>>
>>    public Connection getConnection() throws SQLException {
>>        return DriverManager.getConnection(this.uri, this.username,
>>this.password);
>>    }
>>
>>    public Connection getConnection(String username, String password)
>>throws SQLException {
>>        return DriverManager.getConnection(this.uri, username,
>>password);
>>    }
>>
>>    public PrintWriter getLogWriter() throws SQLException {
>>        return DriverManager.getLogWriter();
>>    }
>>
>>    public void setLogWriter(PrintWriter logWriter) throws SQLException
>>{
>>        DriverManager.setLogWriter(logWriter);
>>    }
>>
>>    public void setLoginTimeout(int timeout) throws SQLException {
>>        DriverManager.setLoginTimeout(timeout);
>>    }
>>
>>    public int getLoginTimeout() throws SQLException {
>>        return DriverManager.getLoginTimeout();
>>    }
>>
>>}
>>    
>>
>
>
>Get Firefox!
>http://www.mozilla.org/firefox/
>
>
>		
>____________________________________________________
>Start your day with Yahoo! - make it your home page 
>http://www.yahoo.com/r/hs 
> 
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: commons-dev-help@jakarta.apache.org
>
>  
>

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Re: [dbutils] SystemDataSource

Posted by David Graham <gr...@yahoo.com>.
Why not just use a real DataSource from C3P0 or Proxool?  They're fully
featured and easy to setup.  Also, we should not use properties named
jdbc.* as they are potentially used by drivers.

http://sourceforge.net/projects/c3p0
http://proxool.sourceforge.net/

David

--- Henri Yandell <fl...@gmail.com> wrote:

> Just had need to hack together a simple DataSource class and wondered
> if it would fit nicely in dbutils. Name is either SystemDataSource
> (after SystemClassLoader) or DriverManagerDataSource, it uses Java -D
> properties and the DriverManager, so is very lightweight and something
> nice to start with before moving up to a container that supplies a
> real DataSource.
> 
> I imagine there are MockDataSources out there that are similar too for
> unit testing, but nothing in DbUtils yet.
> 
> (code follows, it's pretty dumb)
> 
> public class SystemDataSource implements DataSource {
> 
>     private String driver = System.getProperty("jdbc.driver");
>     private String username = System.getProperty("jdbc.user");
>     private String password = System.getProperty("jdbc.password");
>     private String uri = System.getProperty("jdbc.uri");
> 
>     public SystemDataSource() {
>         DbUtils.loadDriver(driver);
>     }
> 
>     public Connection getConnection() throws SQLException {
>         return DriverManager.getConnection(this.uri, this.username,
> this.password);
>     }
> 
>     public Connection getConnection(String username, String password)
> throws SQLException {
>         return DriverManager.getConnection(this.uri, username,
> password);
>     }
> 
>     public PrintWriter getLogWriter() throws SQLException {
>         return DriverManager.getLogWriter();
>     }
> 
>     public void setLogWriter(PrintWriter logWriter) throws SQLException
> {
>         DriverManager.setLogWriter(logWriter);
>     }
> 
>     public void setLoginTimeout(int timeout) throws SQLException {
>         DriverManager.setLoginTimeout(timeout);
>     }
> 
>     public int getLoginTimeout() throws SQLException {
>         return DriverManager.getLoginTimeout();
>     }
> 
> }


Get Firefox!
http://www.mozilla.org/firefox/


		
____________________________________________________
Start your day with Yahoo! - make it your home page 
http://www.yahoo.com/r/hs 
 

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org