You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by Norbert Rieger <no...@web.de> on 2006/04/27 10:46:45 UTC

Connecting to db with user/password not from database.properties

Hi,

I want to connect to my database with a username/password which can not be
put into a property file, it will be given by an user input.
So the <properties ...> tag in sql-map-config.xml can't be used.

How can I specify these values in my java file (iBATIS-API) ?

I tried:

      Properties props = new Properties () ;

      props.setProperty ("url",      "jdbc:postgresql://server/appl-db") ;
      props.setProperty ("driver",   "org.postgresql.Driver") ;
      props.setProperty ("username", ".....") ;
      props.setProperty ("password", ".....") ;

      String resource = "webapps/base/persistence/dao.xml";
      Reader reader = Resources.getResourceAsReader(resource);
      return DaoManagerBuilder.buildDaoManager(reader, props);


but I think the "props" for buildDaoManager are not what I'm looking for,
iBATIS always takes the JDBC parameters (url,driver,user,pwd) from the
property file,
if omitted I get an error message:

ERROR [http-80-Processor21] - SimpleDataSource: Error while loading
properties. Cause: java.lang.ClassNotFoundException: driver
java.lang.ClassNotFoundException: driver

I think this is because "${driver}" can't be replaced and therefore it
evaluates to "driver".

sql-map-config.xml:

  <transactionManager type="JDBC">
    <dataSource type="SIMPLE">
      <property value="${driver}" name="JDBC.Driver"/>
      <property value="${url}" name="JDBC.ConnectionURL"/>
      <property value="${username}" name="JDBC.Username"/>
      <property value="${password}" name="JDBC.Password"/>
    </dataSource>
  </transactionManager>


How can I specify my (dynamic) JDBC parameters at runtime  ?

Any help is appreciated.

Thanx a lot

Norbert