Solved

How to Connect Oracle 9i by using Struts

Posted on 2003-10-28
12
508 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

688 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