Jiyang,
I posted this one back to the group to see if anyone else had run into
this problem. The general problem is that the SQL extension was never really designed to perform insert/update operations. Depending on what
version of Xalan you are using, the pquery code either performed an execute or executeQuery. Currently it is executeQuery, where we are probably running into problem is that an Update does not return and
records or even metadata. I would do two things.
1) Using your exact XSL code, perform a Query. Make sure this is not just a generic bug.
2) Search the list, I know some others were using the SQL extensions to execute stored procedures which I think would have the same problems. There
was some example code in those threads that may be of some help.
3) Run Xalan in a debugger and look at the SQLDocument#execute method to see
where the problem is occurring. If there is a fix that won't adversely affect the query operations, we can add it to the code base.
Regards John G
Jiyang Hu wrote:
Dear John,
I used your pquery example as reference to test my xsl stylesheet which need work for an insertion. My sample code is straightforward but I always catch a nullpoinerexception. I am wondering if you can provide me an example code which has an insert statement. I am using Oracle and I can execute select statement without any trouble. Following is my code and your any comment is welcome, thanks!
Jiyang
<?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:sql="org.apache.xalan.lib.sql.XConnection" extension-element-prefixes="sql"> <xsl:output method="xml" indent="yes"/> <xsl:variable name="value1" select="111"/> <xsl:variable name="value2" select="'hu'"/> <xsl:param name="q1" select="'insert into emp values(?, ?)'"/> <xsl:param name="cinfo" select="//DBINFO"/> <xsl:template match="/"> <xsl:variable name="db" select="sql:new()"/> <xsl:if test="not(sql:connect($db, $cinfo))"> <xsl:message>Error Connecting to the Database</xsl:message> <xsl:copy-of select="sql:getError($db)/ext-error"/> </xsl:if> <xsl:value-of select="sql:addParameter($db, $value1)"/> <xsl:value-of select="sql:addParameter($db, $value2)"/> <xsl:variable name="table" select='sql:pquery($db, $q1,"int, string")'/> <xsl:if test="not($table)"> <xsl:message>Error in Query</xsl:message> <xsl:copy-of select="sql:getError($db)/ext-error"/> </xsl:if> <xsl:value-of select="sql:close($db)"/> </xsl:template> </xsl:stylesheet>
