Announcement Announcement Module
No announcement yet.
Connection DataSource Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Connection DataSource

    I'm new in Spring.
    I'm building a sample web application for testing this framework.
    I have a issue:
    my application start with a web form Login (implemented with JSF, but i think this is not very important for issue)
    and I want to access a database datas (for example a Firebird database).
    I saw in most example a configuration of this type for data access:

      <bean id="placeholderConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
      <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName"><value>$&#123;jdbc.driverClassName&#125;</value></property>
        <property name="url"><value>$&#123;jdbc.url&#125;</value></property>
        <property name="username"><value>$&#123;jdbc.username&#125;</value></property> 
        <property name="password"><value>$&#123;jdbc.password&#125;</value></property>
    The properties username and password are fixed (although I use a file properties).
    How can make Login with dinamical userId and password of DataSource?
    ApplicationContext is initialized at start of my Tomcat, while I would want dinamical userid and password
    for all my access data.
    A poor solution could be passing password and userId as parameter in this fashion:

    public class myDAOJdbc implements myDAOInterface&#123;
      private DataSource datasource;
      public void setDatasource&#40;DataSource datasource&#41; &#123;
            this.datasource = datasource;
      public List getData&#40;String userId, String password&#41; &#123;
        JdbcTemplate jt = new JdbcTemplate&#40;datasource&#41;;
        return "some List";
    but don't like it too much. I wouldn't parameters.
    I wish I can to config my Applicationcontext after my first Login operation with current
    inserted userid and password of dataSource.
    Someone have better ideas?
    Thanks very much for any feedback.

  • #2
    Where do the username and password come from? How are they known?


    • #3
      In my application username and password are insert by the user through
      two input text in a jsf login page.
      But I think they could come from anywhere outside my applicationContext.
      Is possibile, after this autentication, the subsequent jsf pages access to database through
      applicationContext with the datasource username and password inserted?
      They are the username and password of DBMS.