Solved

How to Connect Oracle 9i by using Struts

Posted on 2003-10-28
12
504 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
ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

 
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
 
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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

777 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