You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by an...@telenor.com on 2001/08/01 14:28:14 UTC

RE: Connecting database and XML pages

Thank you, Olivier, you helped me to get started!

I'm running c1.8.2 so I implemented your example.

But when I try to open the pages, I get a java.lang.ClassNotFoundException.
The same happens when I try to open pages from cocoon/samples/sql. I guess I
have done a little and ridiculous mistake somewhere, but I need some hints
as to what could be wrong...

Thanx for your time!
/Anne Marie

-----Original Message-----
From: JEULIN Olivier [mailto:olivier.jeulin@xml-ais.com]
Sent: 31. juli 2001 13:26
To: 'cocoon-users@xml.apache.org'
Subject: RE: Connecting database and XML pages


As usual here, you forgot to tell which version of cocoon you're using...
Here is an (short!) example of what you can do with C1.8.2 (it may slightly
differ with C2):

<xsp:page
xmlns:xsp="http://www.apache.org/1999/XSP/Core"
xmlns:auth="http://ulim.cocoonhost.com/auth"
xmlns:request="http://www.apache.org/1999/XSP/Request"
xmlns:session="http://www.apache.org/1999/XSP/Session"
xmlns:foo="http://localhost/foo"
xmlns:esql="http://apache.org/cocoon/SQL/v2"
xmlns:util="http://www.apache.org/1999/XSP/Util"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xinclude="http://www.w3.org/1999/XML/xinclude"
>

[...]

<esql:connection>
	<esql:pool>foo</esql:pool> <!-- which DB ? --> 

	<esql:execute-query>
	  <esql:query>
	  	select b.ref as ref b.quantite as nb
	  	from basket b
	  	where b.id = <request:get-parameter name="fragResultID"/>
<!-- using a HTTP req. param. -->
	  </esql:query>
	
	  <esql:results>
	     <esql:row-results> <!-- repeated for each row in the result set
-->
	     	<foo:basket>
	     		<foo:item-ref><esql:get-string
column="ref"/></foo:item-ref>
	     		<foo:item-nb><esql:get-int
column="nb"/></foo:item-nb>
	     	</foo:basket>
	     </esql:row-results>
	  </esql:results>

	  <esql:no-results> <!-- if we don't get anything -->
		<!-- whatever -->
	  </esql:no-results>

	</esql:execute-query>
</esql:connection>

[more ...]
</xsp:page>

You can retrieve different kind of data, even XML (read the doc, and
esql.xsd in the samples/sql directory)

##########################################################

You can connect directly to the DB (with user ID & pwd) or, much better,
using a connection pool.
Here is mine (from cocoon.properties), using a DB named foo:

# Turbine DB Connection Pool
############################

# These are your database settings, look in the
# org.apache.turbine.util.db.pool.* package for more information.

processor.xsp.pool.database.foo.driver=org.gjt.mm.mysql.Driver
processor.xsp.pool.database.foo.url=jdbc:mysql://your.mysql.server/foo
processor.xsp.pool.database.foo.username=foouser
processor.xsp.pool.database.foo.password=foopwd
processor.xsp.pool.database.foo.maxConnections=5
processor.xsp.pool.database.foo.expiryTime=3600000
[...]
# These are the supported jdbc-drivers and their adaptors.
# These properties are used by the DBFactory.
processor.xsp.pool.database.adaptor=DBMM
processor.xsp.pool.database.adaptor.DBMM=org.gjt.mm.mysql.Driver

You will need the JDBC adaptater for mysql (see the official mysql site,
sun's JDBC section, or search the list's archives about it)

HTH,
Olivier

> -----Message d'origine-----
> De : annemarie.hartvigsen@telenor.com
> [mailto:annemarie.hartvigsen@telenor.com]
> Envoyé : mardi 31 juillet 2001 09:08
> À : cocoon-users@xml.apache.org
> Objet : Connecting database and XML pages
> 
> 
> Hi,
> 
> I have a mySQL database. I also have a web server: 
> Apache-Tomcat-Cocoon. I
> want to make web pages written in XML, transformed to HTML or 
> WML by the
> help of Cocoon. These pages will serve as an interface to the 
> database.
> 
> What is the best way to connect the database with the XML 
> pages? My users
> should be able to read and write in the database.
> 
> Any tips, suggestions, experiences and examples are greatly 
> appreciated!
> 
> /Anne Marie

---------------------------------------------------------------------
Please check that your question has not already been answered in the
FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>

To unsubscribe, e-mail: <co...@xml.apache.org>
For additional commands, e-mail: <co...@xml.apache.org>

---------------------------------------------------------------------
Please check that your question has not already been answered in the
FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>

To unsubscribe, e-mail: <co...@xml.apache.org>
For additional commands, e-mail: <co...@xml.apache.org>