Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » Tomcat Users »

RE: JDBC from TagSupport

Hart, Justin

2003-12-16


Cool, thanks.

-----Original Message-----
From: Alan Czajkowski [mailto:Alan.Czajkowski@(protected)]
Sent: Tuesday, December 16, 2003 2:44 PM
To: Tomcat Users List
Subject: RE: JDBC from TagSupport


affirmative,

but instead of looking at my proprietary example below .. goto the Tomcat
Documentation under JNDI Datasource HOW-TO and there it explained nicely
on how to do everything







Thanks,

Alan Czajkowski
-------------------------------------
Database Administrator
BMO Financial Group
Decision Support Services
3300 Bloor Street West
14th Floor, West Tower
Toronto, Ontario, M8X 2X2
Tel: 416.232.8736
-------------------------------------




"Hart, Justin" <JHart@(protected)>
16/12/2003 02:38 PM
Please respond to "Tomcat Users List"


    To:   "Tomcat Users List" <tomcat-user@(protected)>
    cc:
    Subject:     RE: JDBC from TagSupport

Gotcha, so the datasource gets stuck into a naming directory, and then you
can grab it via JNDI and use it that way.

The benefit being that a sysadmin can change the datasource via server.xml
rather than having you rewrite the code.

Right?

Justin

-----Original Message-----
From: Alan Czajkowski [mailto:Alan.Czajkowski@(protected)]
Sent: Tuesday, December 16, 2003 2:37 PM
To: Tomcat Users List
Subject: RE: JDBC from TagSupport


i have it setup for sybase and mine looks like this in the server.xml:
---------------------------------------------------------------------------------
<Context path="/Sybase"
docBase="sybase"
debug="5"
reloadable="true"
crossContext="true">

<Logger className="org.apache.catalina.logger.FileLogger"
prefix="localhost_Sybase.log."
suffix=".txt"
timestamp="true"/>

<Resource name="jdbc/a_sybase_datasource"
auth="Container"
type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/a_sybase_datasource">

<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>

<parameter>
<name>maxActive</name>
<value>10</value>
</parameter>

<parameter>
<name>maxIdle</name>
<value>5</value>
</parameter>

<parameter>
<name>maxWait</name>
<value>10000</value>
</parameter>

<parameter>
<name>driverClassName</name>
<value>com.sybase.jdbc2.jdbc.SybDriver</value>
</parameter>

<parameter>
<name>url</name>
<value>jdbc:sybase:Tds:database_hostname:5000/your_dbname?JCONNECT_VERSION=6</value>
</parameter>

<parameter>
<name>username</name>
<value>your_userid</value>
</parameter>

<parameter>
<name>password</name>
<value>your_password</value>
</parameter>

</ResourceParams>
</Context>
---------------------------------------------------------------------------------

of course i also got a .jar file (jConnect 5.5) from sybase that i guess
provides the "com.sybase.jdbc2.jdbc.SybDriver"


and then in the JSP u have something like this to reference the context
and setup the connection:
---------------------------------------------------------------------------------
 String s = "java:comp/env";
 String t = "jdbc/a_sybase_datasource";
 InitialContext initCtx = null;
 try
 {
   initCtx = new InitialContext();
 }
 catch(Exception e)
 {
   out.println("<BR />");
   out.println("<BR />");
   out.println("<PRE>failed: initCtx = new InitialContext();");
   out.println(e + " : " + e.getMessage());
   out.println("</PRE><BR />");
 }
 Context envCtx = null;
 try
 {
   envCtx = (Context)initCtx.lookup(s);
 }
 catch(Exception e)
 {
   out.println("<BR />");
   out.println("<BR />");
   out.println("<PRE>failed: envCtx = (Context)initCtx.lookup(" + s +
");");
   out.println(e + " : " + e.getMessage());
   out.println("</PRE><BR />");
 }
 DataSource ds = null;
 try
 {
   ds = (DataSource)envCtx.lookup(t);
 }
 catch(Exception e)
 {
   out.println("<BR />");
   out.println("<BR />");
   out.println("<PRE>failed: ds = (DataSource)envCtx.lookup(" + t +
");");
   out.println(e + " : " + e.getMessage());
   out.println("</PRE><BR />");
 }
 if(ds == null)
 {
   out.println("<BR />");
   out.println("<BR />");
   out.println("<PRE>warning: DataSource is null");
   out.println("</PRE><BR />");
 }

 Connection conn;
 Statement stmt;
 ResultSet rs;

 // open connection object
 conn = ds.getConnection();
 // open statement object
 stmt = conn.createStatement();
---------------------------------------------------------------------------------




Thanks,

Alan Czajkowski
-------------------------------------
Database Administrator
BMO Financial Group
Decision Support Services
3300 Bloor Street West
14th Floor, West Tower
Toronto, Ontario, M8X 2X2
Tel: 416.232.8736
-------------------------------------




"Hart, Justin" <JHart@(protected)>
16/12/2003 02:26 PM
Please respond to "Tomcat Users List"


    To:   "Tomcat Users List" <tomcat-user@(protected)>
    cc:
    Subject:     RE: JDBC from TagSupport

Ok, so, how does one access this datasource from tagsupport?

Justin

-----Original Message-----
From: Philipp Taprogge [mailto:Philipp.Taprogge@(protected)]
Sent: Tuesday, December 16, 2003 2:24 PM
To: Tomcat Users List
Subject: Re: JDBC from TagSupport


Hi!

Hart, Justin wrote:
> Quick question. I see that one can configure a JDBC datasource in their

server.xml file and their web.xml file.
> What does this get you? Every example that I have read tells me
that I need to open a JDBC connection just about
> the same as I would from any other java application.
>
> What is the purpose of setting up a JDBC datasource in these files? Is
it only good for userdatabaserealm?

The main advantage is that you can use a connection pool like
jakarta-commons-dbcp which saves you a lot of runtime. The second
advantage is that you can configure the connection parameters like db
URL, username, password and the like on the fly without editing java
sources or redeploying your application.

          Phil


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@(protected)
For additional commands, e-mail: tomcat-user-help@(protected)


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@(protected)
For additional commands, e-mail: tomcat-user-help@(protected)




---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@(protected)
For additional commands, e-mail: tomcat-user-help@(protected)




---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@(protected)
For additional commands, e-mail: tomcat-user-help@(protected)



©2008 junlu.com - Jax Systems, LLC, U.S.A.