You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by "M. Homayoun Pourheidari" <ho...@hp.com> on 2000/07/31 19:01:35 UTC

xsp/sql problems

Hi,

I'm trying to understand how the xsp works and I'm running into two
issues:

1)
I took the xsp example that was provided in the sql directory and got it

to work :)

Then I changed the query statement from a select to an insert and I
insert a simple key, value pair ('k4', 'v4');

-- taglib2.xml--

<?xml version="1.0"?>

<?cocoon-process type="xsp"?>
<?cocoon-process type="xslt"?>
<!-- <?xml-stylesheet href="taglib2.xsl" type="text/xsl"?> -->

<xsp:page
  language="java"
  xmlns:sql="http://www.apache.org/1999/SQL"
  xmlns:xsp="http://www.apache.org/1999/XSP/Core"
>

  <page title="SQL Search Results">

   <sql:execute-query>
                <sql:driver>oracle.jdbc.driver.OracleDriver</sql:driver>

                <sql:dburl>myurl</sql:dburl>
  <sql:doc-element>rowset</sql:doc-element>
  <sql:row-element>row</sql:row-element>
  <sql:username>muusername</sql:username>
  <sql:password>mypasswd</sql:password>
  <sql:tag-case>lower</sql:tag-case>
  <sql:null-indicator>yes</sql:null-indicator>
  <sql:id-attribute-column>key</sql:id-attribute-column>
  <sql:query>insert into dummy values('k4','v4')</sql:query>
 </sql:execute-query>

  </page>

</xsp:page>

--

Once I run it, I get the following error message.

Error found handling the request.
java.lang.ArrayIndexOutOfBoundsException
 at org.apache.xerces.dom.DocumentImpl.isXMLName(DocumentImpl.java:1245)

 at
org.apache.xerces.dom.DocumentImpl.createAttribute(DocumentImpl.java:322)

 at org.apache.xerces.dom.ElementImpl.setAttribute(ElementImpl.java:414)

 at

org.apache.cocoon.processor.xsp.library.sql.XSPSQLLibrary.processQuery(XSPSQLLibrary.java:147)

 at _C_._web._db._taglib3.populateDocument(_taglib3.java:87)
 at org.apache.cocoon.processor.xsp.XSPPage.getDocument(XSPPage.java:96)

 at
org.apache.cocoon.processor.xsp.XSPProcessor.process(XSPProcessor.java:456)

 at org.apache.cocoon.Engine.handle(Engine.java:305)
 at org.apache.cocoon.Cocoon.service(Cocoon.java:167)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:588)
 at
org.apache.jserv.JServConnection.processRequest(JServConnection.java:314)

 at org.apache.jserv.JServConnection.run(JServConnection.java:188)
 at java.lang.Thread.run(Unknown Source)

but it does actually insert the values ('k4','v4') into my dummy table?
Can someone tell me why I'm getting this error message and what do I
need to do to prevent it?

2)
Since I really want to separate my data from my xsp processing, I
pressed on by creating a simple xml file:

-- writedb.xml --

<?xml version="1.0"?>

<?cocoon-process type="xslt"?>
<?xml-stylesheet href="writedb.xsp.xsl" type="text/xsl"?>

  <page>
   <db>
    <row>
      <key>k4</key>
      <value>v4</value>
    </row>
   </db>
  </page>

and moving all of my xsp processing to "writedb.xsp.xsl".  So, I want my

xsp file to read my xml file, take all the row values and convert them
into insert statements.  Here is the xsp.

-- writedb.xsp.xsl --

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
   xmlns:sql="http://www.apache.org/1999/SQL"
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   xmlns:xsp="http://www.apache.org/1999/XSP/Core"
>

  <xsl:template match="page">
    <xsl:processing-instruction
name="cocoon-process">type="xsp"</xsl:processing-instruction>
    <xsl:processing-instruction
name="cocoon-process">type="xslt"</xsl:processing-instruction>

    <xsp:page
      language="java"
      xmlns:sql="http://www.apache.org/1999/SQL"
      xmlns:xsp="http://www.apache.org/1999/XSP/Core"
    >

      <xsp:logic>
       private void insertDB(String key, String value) {
          <sql:query>insert into dummy values(key, value)</sql:query>
<!-- here I try to insert into the DB -->
       }
       </xsp:logic>

    <sql:execute-query>
       <xsl:apply-templates/>
    </sql:execute-query>

    </xsp:page>
  </xsl:template>

  <xsl:template match="db">
      <sql:driver>oracle.jdbc.driver.OracleDriver</sql:driver>
      <sql:dburl>myurl</sql:dburl>
      <sql:username>myusername</sql:username>
      <sql:password>mypasswd</sql:password>
      <sql:doc-element>db</sql:doc-element>
      <sql:row-element>row</sql:row-element>
      <sql:tag-case>lower</sql:tag-case>
      <sql:null-indicator>yes</sql:null-indicator>
      <sql:id-attribute-column>key</sql:id-attribute-column>
      <xsl:apply-templates select="row"/>
  </xsl:template>

  <xsl:template match="row">
    <xsp:expr>
         insertDB(request.get<xsl:value-of select="key"/>(),
                        request.get<xsl:value-of select="value"/>());
    </xsp:expr>
  </xsl:template>

</xsl:stylesheet>

But it doesn't work and I get a compilation error.  I think the problem
has something to do with the way I'm building my structures and query
but I can't quite figure out what xsp wants to see?

Can anyone shed some light on these two problems for me?

Thanks in advance,
H.