Solved

How to Connect Oracle 9i by using Struts

Posted on 2003-10-28
12
503 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

895 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

12 Experts available now in Live!

Get 1:1 Help Now