ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Norbert Rieger" <norbert-rie...@web.de>
Subject Connecting to db with user/password not from database.properties
Date Thu, 27 Apr 2006 08:46:45 GMT
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


Mime
View raw message