Announcement Announcement Module
Collapse
No announcement yet.
Newbie Question - Difficulty configuring app to work with Oracle DB Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Newbie Question - Difficulty configuring app to work with Oracle DB

    Hi,

    Really new to Spring - and have tried to work through the Spring Ref Docs (esp. Section 3) - and I'm getting nowhere fast! There is so much to know about beans etc (also not something I am too used too yet).

    I am trying to adapt the following example code I found below to work with the Oracle Driver:

    Code:
    OracleDao dao = new OracleDao();
    			DriverManagerDataSource dataSource = new DriverManagerDataSource();
    			dataSource.setDriverClassName("org.apache.derby.jdbc.EmbeddedDriver");
    			dataSource.setUrl("jdbc:derby:c:\\temp\\database\\test01;create=false");
    			dataSource.setUsername("");
    			dataSource.setPassword("");
    
    			// Inject the datasource into the dao
    			dao.setDataSource(dataSource);
    So ignore the Derby stuff -I think this kind of thing can be wired up in a configuration XML file, which I think is stored in WEB-INF folder - can somone explain how you do that step and how it is you wire that up to some java code?

    However I might be totally wrong in my thinking here - so apologies.

    Many thanks

  • #2
    Hello,

    I suggest that you read
    http://static.springframework.org/sp...nce/beans.html
    first. You dont have to understand all of it, but you will get a good picture.

    You can configure your dataSource in the config. You will configure your
    Hibernate(?) session in the config too, and let Spring inject the dataSource
    into the session.

    So all you have to do in your code, is to work with the hibernate session .

    This is my config in the moment:
    Code:
    ....
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
            <property name="driverClassName" value="${db.driver}"/>
            <property name="url" value="${db.url}"/>
            <property name="username" value="${db.user}"/>
            <property name="password" value="${db.password}"/>
    </bean>
    
    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
            <property name="dataSource" ref="dataSource"/>
            <property name="jpaVendorAdapter">
                <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                    <property name="showSql" value="true" />
                    <property name="generateDdl" value="true"/>
                    <property name="databasePlatform" value="org.hibernate.dialect.MySQL5Dialect" />
                    <property name="database" value="MYSQL"/>
                </bean>
            </property>
            <property name="jpaDialect">
                <bean id="jpaDialect" class="org.springframework.orm.jpa.vendor.HibernateJpaDialect"/>
            </property>
    </bean>
    ....
    best regards

    Comment


    • #3
      Do I need Spring???

      Just reading about Hibernate - sounds like it will do most of what I need, which is fairly basic - do I really need to bother with Spring as well?

      I just want to do some fairly basic inserts into 2 tables - parent and child relationship.

      Comment


      • #4
        Hello,

        for a really smal project, without future :o, you can call and instance your
        objects directly. But I think it is a good thing to know about spring

        Comment

        Working...
        X