YYYYYYYYYYYEEEEEEEEESSSSSSSS!!! It worked... exaclty the way I wanted. Perfect..
 
Thanks a lot!
 
But now I have another problem, which I had before this one that I just "skipped"... 
this may be simpler for you guys to solve...
 
I need to place my classes (unpackaged) in \common\classes AND the oracle driver 
(packaged or unpackaged) in \common\classes or \common\lib... but that doesn't seem to 
work... altough my classes are found troughout all webapps, the oracle driver is not...
 
why??
 
.:| Christian J. Dechery
.:| FINEP - Depto. de Sistemas
.:| [EMAIL PROTECTED]
.:| (21) 2555-0332

>>> [EMAIL PROTECTED] 10/07/02 17:22 >>> 
Hi, 

Let me see if I understand your problem. You have a JSP that creates 
"business objects", the business object internally used some "DAO objects", 
each DAO object when it performs it's processing calls "DAO.getConnection" 
(this happens to take some parameters which I assume are hardwired into 
DAOMain). 

Because you have a lot of JSP's your easiest (but not the simplest!) 
solution is to use JNDI. You could use parameters but then you would have to 
modify every single JSP. 

To each context add an environment entry of the following type: 
<Context ...........> 
...... 
<Environment name="db.url" type="java.lang.String" 
value="jdbc:postgres://localhost/mydb" /> 
</Context> 

To read this value you need code of the following form (courtesy Will 
Hartung), you can add it anywhere, in your DAOMain, business object, etc. 
You probably want to add it to the function that initialises your database 
parameters. 

import javax.naming.*; 

InitialContext ctx = new InitialContext(); 
String dbUrl= (String)ctx.lookup("java:comp/env/db.url"); 

I have tested this Tomcat 4.1.7. 

Regards. 

----- Original Message ----- 
From: "Christian J. Dechery" < [EMAIL PROTECTED] > 
To: < [EMAIL PROTECTED] > 
Sent: Wednesday, July 10, 2002 8:16 PM 
Subject: Big problem 2, the Mission! 


First I would like to thank all of you for ur patience with me... 

my problem is I HATE reading documentation and references. I'm a 
trial-and-error developer... sometimes that's good, and sometimes (like 
today) it is not. 

I will now try to explain my problem with some code to be sure I won't get 
missunderstood. 

But before anything... I don't have ANY Servlets here... I was totally 
tripping... I tought a Servlet was the solution, but it is not. 

I only have JSPs (which I know are Servlets) and Beans. 

let's go: 

I have a webapp with lots of JSPs and classes... in my JSPs I have something 
like this: 
<%@page import="SomeBusinessObject"%> 

<% 
SomeBusinessObject sbo = new SomeBusinessObject(); 
sbo.setParameters( request.getParameter("id1"), 
request.getParameter("id2") ); 

sbo.getSomeAttribute(); 
sbo.setSomeAttribute(); 
sbo.update(); sbo.delete()... etc.. etc... 

... lots of other code... 
%> 

this SomeBusinessObject will have a reference to a DAOSomeBusinessObject 
where all the queries (insert, delete, update, select) resides... and that 
setParameters() method is only for it to know which row of the database 
we're handling with, the parameters match with the table keys of course. But 
that is irrelevant here. 
I have also a class called DAO which provides all of the other DAO*s with a 
Connection... this is done internally within each DAO*. 

the method bellow is in DAO, which all the other DAO*s call to get the 
Connection. 

public static synchronized Connection getConnection(String usr, String pwd, 
String url, String driver) { 
Connection con = null; 

// some code here to make some checks... irrelevant.... 

try { 
Class.forName( driver ); 
con = DriverManager.getConnection(url, usr, pwd); 
} catch(ClassNotFoundException cnf) { 
System.out.println ("*** Erro: driver nao encontrado! 
"+cnf.getMessage()); 
} catch(SQLException sql) { 
String detalhes = "URL = "+url+"\nUSER = "+usr+"\nPWD = "+pwd; 
System.out.println("*** Erro ao obter conex�o! 
"+sql.getMessage()+"\n"+detalhes ); 
} 

// a little bit more code.... 

return con; 
} 

now the problem - I'll try to be very clear (my english SUX, please be 
patient with me). 

the webapp points to a specific db URL... this URL is in the DAOMain... if I 
want to change the db, I'll have to change DAOMain, recompile it, and 
overwrite it... nothing weird so far. Right? 

The big thing is: this webapp gets replicated... so I copy the ENTIRE dir... 
classes, JSPs, jars... everything... and I know how stupid this is... and 
that's the problem... 

- in each of these webapps, the only thing that changes is the JSPs, and 
maybe the DB url... 

WHAT I WANT IS: I want to put our classes, jars and the oracle driver in the 
$TOMCAT_HOME\common dir, because they don't change from one webapp to 
another.... BUT since DAOMain holds the URL this is not possible (each 
webapp must have its own DAOMain)... I wanna create a CLASS that will 
receive a request from DAO or DAOMain (residing in \common) and provide a 
Connection based on the Context of the JSP that used SomeBusinessObject -> 
DAOSomeBusinessObject -> DAO. 

or maybe DAO could do that... let's say I would write some code in 
getConnection() to find out where (Context) it is (well... actually DAO is 
always in the same place.. but the JSP that uses it, and calls it, is not) 
to provide the right Connection... BUT without ANY change of parameters to 
getConnection(), since that would snowball into a mega change of method's 
signatures that would end in the JSPs... 

(I'm tired...) 

well... that's it... I don't think I can be clearer than that... my english 
stops here... :) 




.:| Christian J. Dechery 
.:| FINEP - Depto. de Sistemas 
.:| [EMAIL PROTECTED] 
.:| (21) 2555-0332 




-- 
To unsubscribe, e-mail: < mailto:[EMAIL PROTECTED] > 
For additional commands, e-mail: < mailto:[EMAIL PROTECTED] > 



Reply via email to