Note that there are some explanatory texts on larger screens.

plurals
  1. POConfiguring username/password with myBatis and c3p0
    text
    copied!<p>I have 2 separate data connections I need to to handle during the lifecycle of a j2ee application. One has all of its properties known before hand and I configure myBatis as so</p> <pre><code> &lt;environment id="development"&gt; &lt;transactionManager type="JDBC" /&gt; &lt;dataSource type="JNDI"&gt; &lt;property name="data_source" value="java:comp/env/jdbc/pooledDS" /&gt; &lt;/dataSource&gt; &lt;/environment&gt; </code></pre> <p>This is great. PooledDS refers to my c3p0 configured data source. The second connection will be created with a username/password combo which is determined when a user logs in to the application. I would like to use c3p0 again for that data source and I attempt to configure mybatis.xml as </p> <pre><code> &lt;environment id="user"&gt; &lt;transactionManager type="JDBC" /&gt; &lt;dataSource type="JNDI"&gt; &lt;property name="data_source" value="java:comp/env/jdbc/pooledDS2" /&gt; &lt;/dataSource&gt; &lt;/environment&gt; </code></pre> <p>My corresponding resource entry in my Tomcat's context.xml is</p> <pre><code> &lt;Resource name="jdbc/pooledDS2" auth="Container" description="DB Connection for Users" driverClass="oracle.jdbc.driver.OracleDriver" maxPoolSize="100" minPoolSize="10" acquireIncrement="1" factory="org.apache.naming.factory.BeanFactory" maxIdleTime="850" type="com.mchange.v2.c3p0.ComboPooledDataSource" jdbcUrl="jdbc:oracle:thin:@localhost:1521:orcl4" /&gt; </code></pre> <p>You see, I leave the user and password attributes blank because I do not know them. When I know the user for whom I need a connection I try the following:</p> <pre><code> Reader reader = Resources.getResourceAsReader(RESOURCE); Properties userProps = new Properties(); userProps.setProperty("user", loginName); userProps.setProperty("username", loginName); userProps.setProperty("password", password); sqlMapperUser = new SqlSessionFactoryBuilder().build(reader, "user", userProps); </code></pre> <p>You see, I try to pass in the username and password as a Property object when I get my SqlSessionFactory. When I look at my log messages in tomcat for c3p0 I see that the c3p0 properties are empty and apparently it never heard from myBatis what the username and password are so it cannot make a connection. I know I am using the correct "user" environment, it is just how do I properly set the username and password for this connection? Thanks for your help.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload