• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Configuring DSN

 
Ranch Hand
Posts: 265
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Ranchers...
I'm using JSP and Oracle for doing a project and the webserver using is Apache Tomcat. Finally in the completing stage i want to upload the war file in to Linux server. So for a test we have to run the JSP pages in the Linux machine. We have installed Redhat Linux Enterprise and installed J2SE 5.0 and configured Apache Tomcat and also the Oracle 10g database in Linux. Now there is a problem. How to congigure Data Source Name, Since for the whole program we used the datasource name for creating the connection.

Now ranchers.. You all have to help us. to do.. so
if we want to edit some configuration file. also .. help me to do so..

Thanks in advance

regards

Aravind Prasad
 
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My favorite tomcat way connect to a database, it to have tomcat provide a JDBC connection pool as a global JNDI resource and then my application gets deployed with mapping a JNDI resource reference (from the web.xml) to the tomcat global JNDI name using the context.xml in my war file.
That way, the application module does not have any dependency on the JDBC url (or DSN, which is really a JDBC URL that goes through jdbc:odbc bridge??)


Here is an example, my system is tomcat 5.5 on linux to connect to PostgreSQL.

1) make sure you have the JDBC driver for your database in your tomcat's boot classpath, such as ${TOMCAT_HOME}/common/lib

2) create entry in your ${TOMCAT_BASE}/conf/server.xml that provides the parameters for how to connect to your database. The following example is from my tomcat 5.5 to PostgreSQL (you will have to change the URL for oracle):


in my case, i give it some name that makes sense to me, fmsDB.
Note the <lobalNamingResources> is probably already there in the server.xml

3) add a resource entry in your web.xml to indicate your application is wanting to use a JDBC resource:



4) package a META-INF/context.xml into your .war file (as the top level path META-INF/context.xml. Tomcat seems to understand this, and if it is present, will perform mappings from the web application specific datasource name to the global datasource name. Here is my META-INF/context.xml:


5) start tomcat, inspect to make sure no start up errors (typos in the server.xml. deploy your app, watch logs for errors in finding database drivers in classpath, typos in web.xml.

6) use something, like a jsp test page, inside your application to validate the connection is good. The data source would be available from the JNDI naming context as java:comp/env/jdbc/fmsDB (in my case)




As a side note, the above pattern works nicely on windows deployments too, without modification, exactly as it is. (i.e. JDBC connection pooling with JNDI bindings, and indirection to your web app module).

I guess my response was more along "don't use DSN / ODBC to connect web apps, which probably does not help, since you are almost done the project.

So, if you must use DSN on the linux box, there are ODBC implementations available for unix / linux: iodbc.org and easysoft's UnixODBC.
When one of these is installed and configured with a DSN to your Oracle server, the Tomcat JDBC connect URL, or how ever you currently connect to the DSN with in your app, should be able to use it.
[ June 15, 2006: Message edited by: Travis Hein ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic