ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Larry Meadors" <lmead...@apache.org>
Subject Re: Dynamically passing username/password while create JDBC connection in buildDaoManager
Date Mon, 24 Jul 2006 19:43:01 GMT
Un-comment this:

<property name="JDBC.Username" value="${username}" />
<property name="JDBC.Password" value="${password}" />

...then change this:

Properties daoProp = new Properties();
daoProp.put("JDBC.username", username);
daoProp.put("JDBC.password", password);

...to this:

Properties daoProp = new Properties();
daoProp.put("username", username);
daoProp.put("password", password);

... then comment these out in the properties file:
#username= fakeusername
#password= fakepassword

...and it should work just fine.

Larry


On 7/24/06, Christina Xu <christxu@yahoo.com> wrote:
> Sure. Here is the whole thing. Please help.
>
> -- sql-map-config.xml
> <!DOCTYPE sqlMapConfig PUBLIC
> "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN"
>     "http://www.ibatis.com/dtd/sql-map-config-2.dtd">
> <sqlMapConfig>
>    <properties resource="dataSource.properties" />
>    <settings
>       cacheModelIsEnabled="true"
>       maxSessions="64"
>       maxTransactions="8"
>       maxRequests="128" />
>   <transactionManager type="JDBC" >
>        <dataSource type="SIMPLE" >
>             <property name="JDBC.Driver"
> value="${driver}" />
>         <property name="JDBC.ConnectionURL" value="${url}" />
> <!-- I don't want to put JDBC.Username, JDBC.Password
> here. I would like to pass them from java program. If
> I give real username,password to here or at
> dataSource.properties file, it will of course work.
> -->
> <!--    <property name="JDBC.Username"
> value="${username}" />
>         <property name="JDBC.Password" value="${password}" />
>  -->
>         <property name="JDBC.DefaultAutoCommit" value="false"
> />
>         <property name="Pool.MaximumActiveConnections"
> value="10" />
>         <property name="Pool.MaximumIdleConnections"
> value="15" />
>         <property name="Pool.PingEnabled" value="true" />
>         <property name="Pool.PingQuery" value="select 1 from
> dual" />
>       </dataSource>
>    </transactionManager >
>   <sqlMap resource="contents.xml" />
> </sqlMapConfig>
>
>
>
> -- dataSource.properties
> driver=oracle.jdbc.driver.OracleDriver
> url=jdbc.oracle.thin:@hostname:1521:SID
> ## I don't want to put username here.
> username= fakeusername
> ## I don't want to put username here.
> password= fakepassword
>
> -- java
>
> public void loadDaoManager(String username, String
> password){
> Properties daoProp = new Properties();
> daoProp.put("JDBC.username", username);
> daoProp.put("JDBC.password", password);
> Reader reader =
> Resources.getResourceAsReader(dbSource);
> // I want username , password pass from here
> daoManager = DaoManagerBuilder.buildDaoManager(reader,
> daoProp);
>
> }
>
>
> Thanks a lot !!!
>
>
>
> --- Larry Meadors <lmeadors@apache.org> wrote:
>
> > Can you post your entire sqlmapconfig.xml, please?
> >
> > Larry
> >
> >
> > On 7/24/06, Christina Xu <christxu@yahoo.com> wrote:
> > > How could I put username/password in dao.xml file?
> > >
> > > in dao.xml file I have:
> > >
> > > <!DOCTYPE daoConfig PUBLIC
> > "-//ibatis.apache.org//DTD
> > > DAO Configuration
> > > 2.0//EN" "http://ibatis.apache.org/dtd/dao-2.dtd">
> > > <daoConfig>
> > >      <context>
> > >          <transactionManager type="SQLMAP">
> > >              <property name="SqlMapConfigResource"
> > > value="sql-map-config.xml"/>
> > >          </transactionManager>
> > >
> > >          <dao
> > interface="com.abc.dao.ContentOrderDao"
> > >
> > > implementation="com.abc.dao.sqlmap.SqlMapDao"/>
> > >      </context>
> > >
> > > </daoConfig>
> > >
> > > in sql-map-config.xml file I have:
> > > <sqlMapConfig>
> > >   <properties resource="dataSource.properties" />
> > > </sqlMapConfig>
> > >
> > > So When I put username/password to
> > > dataSource.properties file it works fine. BUT, but
> > > when I put EMPTY username/password (just for
> > > placehold) or fake username/password in
> > > dataSource.properties it brakes.
> > >
> > > driver=oracle.jdbc.driver.OracleDriver
> > > url=jdbc.oracle.thin:@hostname:1521:SID
> > > username=
> > > password=
> > >
> > > The way IBATIS behaive looks like to me it didn't
> > take
> > > the properties passing to the
> > > DaoManagerBuilder.buildDaoManager(reader,
> > properties).
> > >
> > > in java I have:
> > >
> > > Properties daoProp = new Properties();
> > > daoProp.put("JDBC.username", username);
> > > daoProp.put("JDBC.password", password);
> > >
> > > Reader reader =
> > > Resources.getResourceAsReader(dbSource);
> > > daoManager =
> > DaoManagerBuilder.buildDaoManager(reader,
> > > daoProp);
> > >
> > > Should IBatis get this JDBC.username and
> > JDBC.password
> > > from daoProp instead of .xml or other property
> > files.
> > >
> > > Thanks, Help is really needed .
> > >
> > >
> > >
> > >
> > >
> > >
> > > --- Larry Meadors <lmeadors@apache.org> wrote:
> > >
> > > > Oh, OK - you need to add those to the dao.xml
> > file,
> > > > too.
> > > >
> > > > Larry
> > > >
> > > >
> > > > On 7/24/06, Christina Xu <christxu@yahoo.com>
> > wrote:
> > > > > No. I don't have user/password defined in
> > dao.xml.
> > > > Not
> > > > > in any .xml or property files.
> > > > >
> > > > > In dataSource.properties file, I only have
> > > > >
> > > > > driver=oracle.jdbc.driver.OracleDriver
> > > > > url=jdbc.oracle.thin:@hostname:1521:SID
> > > > >
> > > > > Any help is appreciated. Thanks.
> > > > >
> > > > > --- Larry Meadors <lmeadors@apache.org> wrote:
> > > > >
> > > > > > Are there placeholders for the user/password
> > in
> > > > the
> > > > > > dao.xml?
> > > > > >
> > > > > > Larry
> > > > > >
> > > > > >
> > > > > > On 7/24/06, Christina Xu
> > <christxu@yahoo.com>
> > > > wrote:
> > > > > > > Hello All,
> > > > > > >
> > > > > > > I have a requirement to Dynamic set
> > > > > > username/password
> > > > > > > when create JDBC connection. So what I
> > have is
> > > > :
> > > > > > >
> > > > > > > <sqlmapConfig>
> > > > > > >    <properties
> > > > resource="dataSourse.properties" />
> > > > > > >    <transactionManager type="JDBC" >
> > > > > > >       <dataSource type="SIMPLE" >
> > > > > > >       <property name="JDBC.Driver"
> > > > > > value="${driver}"
> > > > > > > />
> > > > > > >       <property name="JDBC.ConnectionURL"
> > > > > > > value="${url}" />
> > > > > > >       <property
> > name="JDBC.DefaultAutoCommit"
> > > > > > > value="false" />
> > > > > > >       ...
> > > > > > >       ...
> > > > > > >     </dataSource>
> > > > > > >    </transactionManager>
> > > > > > > ...
> > > > > > > ...
> > > > > > > </sqlMapConfig>
> > > > > > >
> > > > > > > In java,
> > > > > > >
> > > > > > > public void loadDaoManager(String
> > username,
> > > > String
> > > > > > > password) {
> > > > > > >
> > > > > > > String dbSource="dao.xml"
> > > > > > > Properties daoProp = new Properties();
> > > > > > > daoProp.put("JDBC.username", username);
> > > > > > > daoProp.put("JDBC.password", password);
> > > > > > >
> > > > > > > Reader reader =
> > > > > > > Resources.getResourceAsReader(dbSource);
> > > > > > > daoManager =
> > > > > > >
> > > >
> > DaoManagerBuilder.buildDaoManager(reader.daoProp);
> > > > > > > ...
> > > > > > > ...
> > > > > > >
> > > > > > > }
> > > > > > >
> > > > > > > When I run this, I got Error
> > > > > > >
> > > > > >
> > > >
> > "com.ibatis.common.exception.NestedRuntimeException:
> > > > > > > SimpleDataSource: Some properties were not
> > > > set."
> > > > > > >
> > > > > > > My question is is it possible to Dynamic
> > give
> > > > > > > username/password in the properties
> > instead
> > > > > > hardcode
> > > > > > > in .xml file? If yes, can someone give me
> > > > > > direction on
> > > > > > > how? Thanks a lot.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > >
> > __________________________________________________
> > > > > > > Do You Yahoo!?
> > > > > > > Tired of spam?  Yahoo! Mail has the best
> > spam
> > > > > > protection around
> > > > > > > http://mail.yahoo.com
> > > > > > >
> > > > > >
> > > > >
> > > > >
> > > > >
> > __________________________________________________
> > > > > Do You Yahoo!?
> > > > > Tired of spam?  Yahoo! Mail has the best spam
> > > > protection around
> > > > > http://mail.yahoo.com
> > > > >
> >
> === message truncated ===
>
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
>

Mime
View raw message