Solved

How to Connect Oracle 9i by using Struts

Posted on 2003-10-28
12
502 Views
Last Modified: 2008-02-01
i am using Tomcat 4.1.27 as my web server and i have set classes12.jar to my CLASSPATH, and put the jar file in the library of tomcat, but i can't still get a connection to Oracle 9i

Help me plz..........................

i want to know the following answers
1. How to configure the environment in Tomcat and Window xp when i make
    connection to Oracle 9i by using struts
2. What is the coding to make the connection( giving a example code would be
    better)

Additional Question (option to answer)
3. Where can find sample code of struts except Oracle and Apache Website

P.S.
i am using eclipse as my tools to programming
Thank You for your help.........................
0
Comment
Question by:ronancheung
  • 4
  • 3
  • 3
12 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 68 total points
ID: 9634988
>>but i can't still get a connection to Oracle 9i

Meaning what exactly? Where have you put the jar in Tomcat?

Here's an example datasource config in struts-config.xml:

<struts-config>


  <!-- ========== Data Source Configuration =============================== -->
<!--
 <data-sources>
   <data-source>
     <set-property property="autoCommit"
                      value="false"/>
     <set-property property="description"
                      value="Example Data Source Configuration"/>
     <set-property property="driverClass"
                      value="org.postgresql.Driver"/>
     <set-property property="maxCount"
                      value="4"/>
     <set-property property="minCount"
                      value="2"/>
     <set-property property="password"
                      value="mypassword"/>
     <set-property property="url"
                      value="jdbc:postgresql://localhost/mydatabase"/>
     <set-property property="user"
                      value="myusername"/>
   </data-source>
 </data-sources>
...

</struts-config>
0
 
LVL 2

Assisted Solution

by:f_98
f_98 earned 67 total points
ID: 9635100
1) put classes12 at the WEB-INF/lib directory of your app

then at the struts-config.xml set up a datasource (like the one CEHJ posted)

(i usually use commons for pooling so i have that commons-dbcp at the lib dir)

<data-sources>
   <data-source type="org.apache.commons.dbcp.BasicDataSource" >
    <set-property
      property="driverClassName"
      value="oracle.jdbc.OracleDriver" />
    <set-property
      property="url"
      value="jdbc:oracle:thin:@192.168.0.30:11001:testDB" />
    <set-property
      property="maxActive"
      value="10" />
    <set-property
      property="maxWait"
      value="5000" />
    <set-property
      property="defaultAutoCommit"
      value="false" />
    <set-property
      property="defaultReadOnly"
      value="false" />
    <set-property
      property="validationQuery"
      value="SELECT SYSDATE FROM DUAL" />
    <set-property
      property="username"
      value="testDB" />
    <set-property
      property="password"
      value="testDB" />
   </data-source>
 </data-sources>

2) to get a connection  (in your Action)
import javax.sql.DataSource

DataSource dataSource = getDataSource(request);
Connection conn = dataSource.getConnection();

3) i found lots of good java resource from a certain file sharing network.
0
 

Author Comment

by:ronancheung
ID: 9635276
i use a library like common-dbcp 1.1, but it throws a exception of "no suitable driver", but i have put the driver (classes12.jar) in  WEB-INF/lib folder. but i don't know why?

Help me plz.......................
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9635291
Have you restarted the container since?
0
 

Author Comment

by:ronancheung
ID: 9638016
yes i have retarted the container
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 86

Expert Comment

by:CEHJ
ID: 9640759
Make sure that particular driver class *is in* the jar you put into WEB-INF/lib
0
 

Author Comment

by:ronancheung
ID: 9647112
Thank you for your reply
yes, i have done that
but it still throw a exception of "No suitable Driver"
Help me plz......................
i really want to do that
0
 
LVL 2

Expert Comment

by:f_98
ID: 9648926
try removing all other classes.12 jar in your classpath
like in common/lib, etc.

there's this nasty little "problem/feature" in tomcat about jars being loaded by different classloaders.
0
 
LVL 2

Expert Comment

by:f_98
ID: 9648936
also try removing other instances of dbcp jar in the classpath , just put it in web-inf/lib
0
 

Author Comment

by:ronancheung
ID: 9661573
Now there are no more exception thrown
but i don't know that it really have connected Oralce
Anyone have some sample code
Thank you for all reply!!!!
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now