You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Ivan <if...@latinia.com> on 2001/02/02 17:46:13 UTC

Passing parameters to an xml file to get a select from a DB

I'm sorry to make this question, because it could be out of topic, but i'm getting crazy ...
I was reading some info on this in http://tecfa.unige.ch/guides/xml/cocoon/mysql-xsp/ ,
but it's not exactly the same ...

My file is:

<?xml version="1.0" encoding="iso-8859-1"?>
<?cocoon-process type="xsp"?>
<?cocoon-format type="text/xml"?>
<?xml-logicsheet href="resource://org/apache/cocoon/processor/xsp/library/sql/esql.xsl"?>
<xsp:page language="java" xmlns:esql="http://apache.org/cocoon/SQL/v2" xmlns:xsp="http://www.apache.org/1999/XSP/Core">
<valors>
<xsp:logic>
String country1 = request.getParameter("country1");
String country2 = request.getParameter("country2");
</xsp:logic>
<aa>
<xsp:expr>country1</xsp:expr>
</aa>
<bb>
<xsp:expr>country2</xsp:expr>
</bb>
<esql:execute-query>
<esql:driver>org.gjt.mm.mysql.Driver</esql:driver>
<esql:dburl>jdbc:mysql://localhost/fin</esql:dburl>
<esql:username/>
<esql:password/>
<esql:query>select * from countries where name&gt;='<xsp:expr>country1</xsp:expr>' and name&lt;='<xsp:expr>country2</xsp:expr>'</esql:query>
<esql:results>
<name>
<esql:get-string column="name"/>
</name>
<siglas>
<esql:get-string column="letters"/>
</siglas>
</esql:results>
</esql:execute-query>
</valors>
</xsp:page>


passing the parameters to the file this way : countries.xml?country1=A&country2=C
(ie) to acquire the list of countries from my DB between A and B (included)

The error message goes like this:  

Error found handling the request.

java.lang.Exception: XSP Java Compiler: Compilation failed for _coutries.java
102: Undefined variable: country1 + country1         
105: Undefined variable: country2 + country2);         
2 errors

at org.apache.cocoon.processor.xsp.language.java.XSPJavaProcessor.compile(XSPJavaProcessor.java)
at org.apache.cocoon.processor.xsp.XSPProcessor.process(XSPProcessor.java)  
at org.apache.cocoon.Engine.handle(Engine.java) 
at org.apache.cocoon.Cocoon.service(Cocoon.java) 
at javax.servlet.http.HttpServlet.service(HttpServlet.java:865)  
at org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java)  
at org.apache.tomcat.core.Handler.service(Handler.java) 
at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java)  
at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java)  
at org.apache.tomcat.core.ContextManager.service(ContextManager.java)  
at org.apache.tomcat.service.connector.Ajp12ConnectionHandler.processConnection(Ajp12ConnectionHandler.java)  
at org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java)  
at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java)  
at java.lang.Thread.run(Thread.java:484)

Any idea on this?¿

TIA

Iván Fontán
Technical Department

LATINIA CORPORATION 
www.latinia.com

Spain Office
Barcelona
Trav. Gràcia, 342-344
08025 Barcelona (Spain)
Tel.: +34 934 465 026

US Offices
New York
885 3rd Avenue
Suite 2800
New York, NY 10022

Miami
1210 Brickell Avenue
Suite 430
Miami, FL 33131

Re: Passing parameters to an xml file to get a select from a DB

Posted by Donald Ball <ba...@webslingerZ.com>.
On Fri, 2 Feb 2001, Ivan wrote:

> I'm sorry to make this question, because it could be out of topic, but
> i'm getting crazy ... I was reading some info on this in
> http://tecfa.unige.ch/guides/xml/cocoon/mysql-xsp/ , but it's not
> exactly the same ...
>
> My file is:
>
> <?xml version="1.0" encoding="iso-8859-1"?>
> <?cocoon-process type="xsp"?>
> <?cocoon-format type="text/xml"?>
> <?xml-logicsheet href="resource://org/apache/cocoon/processor/xsp/library/sql/esql.xsl"?>

are you using cocoon-1.8.2 and did you update your cocoon.properties file?
if so, this line is redundant and worse, it'll give you compilation
errors.

> <esql:query>select * from countries where
> name&gt;='<xsp:expr>country1</xsp:expr>' and
> name&lt;='<xsp:expr>country2</xsp:expr>'</esql:query>

use

<esql:query>select * from countries where
  name &gt;= <esql:parameter><request:get-parameter name="country1"/></esql:parameter>
  and name &gt;= <esql:parameter><request:get-parameter name="country2"/></esql:parameter>
</esql:query>

instead to be safer.

> java.lang.Exception: XSP Java Compiler: Compilation failed for _coutries.java
> 102: Undefined variable: country1 + country1
> 105: Undefined variable: country2 + country2);
> 2 errors

that's whacked, it looks like you're doing something else on your page
that you're not showing here. what do you see going on in your source code
around these lines?

- donald