You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-user@tomcat.apache.org by Derek Mahar <DM...@penson.ca> on 2004/05/19 00:28:59 UTC

[JSTL] How do I enter a null value with ?

How do I enter a null value into a table column with <sql:param>?  The
JSTL 1.1 specification states for <sql:param> that, "If value is null,
the parameter is set to the SQL value NULL."  However, no matter what
value I pass to <sql:param>, I'm unable to set a null column:

Case 1: Set value to undefined variable
<sql:update>
  INSERT INTO tblTest(a) VALUES (?)
  <sql:param value="${nullValue}"/>
</sql:update>

Output:
javax.servlet.ServletException: javax.servlet.jsp.JspException: 
  INSERT INTO tblTest(a) VALUES (?)
: [Microsoft][SQLServer 2000 Driver for JDBC]The specified SQL type is
not supported by this driver.

Case 2: Set value to "null"
<c:set var="nullValue" value="null"/>
<sql:update>
  INSERT INTO tblTest(a) VALUES (?)
  <sql:param value="${nullValue}"/>
</sql:update>

Output:
javax.servlet.ServletException: javax.servlet.jsp.JspException: 
  INSERT INTO tblTest(a) VALUES (?)
: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Syntax error
converting the nvarchar value 'null' to a column of data type int.

Cast 3: Set value to empty string
<c:set var="nullValue" value=""/>
<sql:update>
  INSERT INTO tblTest(a) VALUES (?)
  <sql:param value="${nullValue}"/>
</sql:update>

Output:
Microsoft SQL Server inserts a new row with column a set to 0.

Any suggestions?

Derek
NOTICE: This email contains privileged and confidential information and is intended only for the individual to whom it is addressed. If you are not the named addressee, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this transmission by mistake and delete this communication from your system. E-mail transmission cannot be guaranteed to be secured or error-free as information could be intercepted, corrupted, lost, destroyed, arrive late or incomplete, or contain viruses. 

AVIS: Le pr�sent courriel contient des renseignements de nature privil�gi�e et confidentielle et n�est destin� qu'� la personne � qui il est adress�. Si vous n��tes pas le destinataire pr�vu, vous �tes par les pr�sentes avis�s que toute diffusion, distribution ou reproduction de cette communication est strictement interdite.� Si vous avez re�u ce courriel par erreur, veuillez en aviser imm�diatement l�exp�diteur et le supprimer de votre syst�me. Notez que la transmission de courriel ne peut en aucun cas �tre consid�r� comme inviolable ou exempt d�erreur puisque les informations qu�il contient pourraient �tre intercept�s, corrompues, perdues, d�truites, arriv�es en retard ou incompl�tes ou contenir un virus. �

---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-user-help@jakarta.apache.org


Re: [JSTL] How do I enter a null value with ?

Posted by Kris Schneider <kr...@dotech.com>.
<sql:param value="${null}"/>

Derek Mahar wrote:
> How do I enter a null value into a table column with <sql:param>?  The
> JSTL 1.1 specification states for <sql:param> that, "If value is null,
> the parameter is set to the SQL value NULL."  However, no matter what
> value I pass to <sql:param>, I'm unable to set a null column:
> 
> Case 1: Set value to undefined variable
> <sql:update>
>   INSERT INTO tblTest(a) VALUES (?)
>   <sql:param value="${nullValue}"/>
> </sql:update>
> 
> Output:
> javax.servlet.ServletException: javax.servlet.jsp.JspException: 
>   INSERT INTO tblTest(a) VALUES (?)
> : [Microsoft][SQLServer 2000 Driver for JDBC]The specified SQL type is
> not supported by this driver.
> 
> Case 2: Set value to "null"
> <c:set var="nullValue" value="null"/>
> <sql:update>
>   INSERT INTO tblTest(a) VALUES (?)
>   <sql:param value="${nullValue}"/>
> </sql:update>
> 
> Output:
> javax.servlet.ServletException: javax.servlet.jsp.JspException: 
>   INSERT INTO tblTest(a) VALUES (?)
> : [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Syntax error
> converting the nvarchar value 'null' to a column of data type int.
> 
> Cast 3: Set value to empty string
> <c:set var="nullValue" value=""/>
> <sql:update>
>   INSERT INTO tblTest(a) VALUES (?)
>   <sql:param value="${nullValue}"/>
> </sql:update>
> 
> Output:
> Microsoft SQL Server inserts a new row with column a set to 0.
> 
> Any suggestions?
> 
> Derek

-- 
Kris Schneider <ma...@dotech.com>
D.O.Tech       <http://www.dotech.com/>



---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-user-help@jakarta.apache.org