Announcement Announcement Module
Collapse
No announcement yet.
JdbcTemplate and datasource setting username and password? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • JdbcTemplate and datasource setting username and password?

    Hey I'm just going through a petclinic example I found on the internet but I'm
    a bit confused with the code of the dataSource bean in the context. I've created my own mySQL database with the username "jay1" and password: "redclone"
    and I need to modify the code from the example to access my
    mySQL database, but I don't know how to change this, could you please
    tell me what the following means and how I set this up so that it uses my
    username and password? I have nod idea what ${jdbc.url}, ${jdbc.username}
    and ${jdbc.password} mean, if you have any links I'd be happy to read.

    Code:
      <property name="url" value="${jdbc.url}" />
            <property name="username" value="${jdbc.username}" />
            <property name="password" value="${jdbc.password}" />

    java code
    Code:
    jdbcTemplate = new JdbcTemplate(Impala.getBean(
                    "dataSource", DataSource.class));

    From petclinic-hibernate-context.xml

    Code:
     <bean id="dataSource"
            class="org.springframework.jdbc.datasource.DriverManagerDataSource">
            <property name="driverClassName"
                value="${jdbc.driverClassName}" />
            <property name="url" value="${jdbc.url}" />
            <property name="username" value="${jdbc.username}" />
            <property name="password" value="${jdbc.password}" />
        </bean>
    Thanks

  • #2
    I figured it out

    I found another spring forum post and it helped me to figure out the problem.

    I checked the hibernate context.xml and found the same type of code at the
    beginning.

    Code:
    <bean id="propertyConfigurer"
            class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
            <property name="locations">
                <list>
                    <value>classpath:mysql.properties</value>
                </list>
            </property>
        </bean>
    All I had to do then was search the example directory and find the mysql.properties file where the
    username and password had been specified for the datbase.

    Cheers

    Comment

    Working...
    X