Results 1 to 5 of 5

Thread: Spring connect to Oracle

  1. #1
    Join Date
    Jan 2011
    Posts
    5

    Default Spring connect to Oracle

    I have a problem is how to use Spring 3 connect to Oracle database.
    Please tell me detail because I'm a newbie
    I'm use Eclipse Helios and Apache Tomcat


    Thanks all

  2. #2
    Join Date
    Jul 2010
    Location
    Venice, Italy
    Posts
    709

    Default

    Well...HOW do you intend to "connect" to the database? Do you intend to use JPA entities, and if so, what will you use as a JPA provider? EJB 3, Hibernate 3, JDO or what? If you don't use JPA will you use or not ORM at all? If not, are you going to use MyBatis SQL Mapper or will you use simple JDBC queries?

    For each and every one of those choices, Spring 3 offers full support facilities so all you need to do is refer to the right section in the reference documentation.

    When you've chosen your strategy and learned how to use it with Spring by studying the documentation and experimenting a bit on your own, then you can come back to the forum with more specific questions.

  3. #3
    Join Date
    Jan 2011
    Posts
    5

    Default

    can you give me an ebook or document about this problem?
    I find some ebook but it too hard to understand

  4. #4
    Join Date
    Jul 2010
    Posts
    19

    Default

    Install SpringSource Tool Suite which has embedded tomcat and add in a jndi resouce to context.xml

    Code:
    <Resource name="jdbc/yourIdentifer" auth="Container"
                  type="javax.sql.DataSource" driverClassName="oracle.jdbc.OracleDriver"
                  url="jdbc:oracle:thin:@dbserver:1521:dbschema"
                  username="dbuser" password="dbpassword" maxActive="20" maxIdle="10"
                  maxWait="-1"/>
    In your spring configuration create a datasource referencing what you created in context.xml

    Code:
    	<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
    		<property name="jndiName" value="jdbc/yourIdentifer" />
    		<property name="resourceRef" value="true" />
    	</bean>
    I had to include ojdbc14.jar in the tomcat lib directory so it can use driverClassName="oracle.jdbc.OracleDriver"

    HTH

  5. #5

    Default

    To connect to oracle in your Spring project you need:
    1. Add this dependency to your pom.xml:
    Code:
    <dependency>
        <groupId>com.oracle.jdbc</groupId>
        <artifactId>ojdbc14</artifactId>
        <version>9.2.0.8</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
    2. Add dataSource to application context file:
    Code:
    <bean id="dataSource"
    		class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    		<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
    		<property name="url" value="${datasource.url}" />
    		<property name="username" value="${datasource.user}" />
    		<property name="password" value="${datasource.password}" />
    
    	</bean>
    3. Use this bean to set your DAOs:
    Code:
    	<bean id="abstractJdbcDAO" abstract="true"
    		class="org.springframework.jdbc.core.simple.SimpleJdbcDaoSupport">
    		<property name="dataSource" ref="dataSource"></property>
    	</bean>
    If you have some questions feel free to aks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •