0
votes

I am having a problem with my jsp page. I am using:-

-Tomcat 8.0.20

-Eclipse Java EE luna SR2

-Microsoft SQL server 2005

-Using management studio express to do my db work

It's a small problem as i am learning to run queries on jsp pages. I have stumbled upon this problem and wondered if anyone can help me.

this is my code snippet

 <sql:setDataSource var="snapshot" river="com.microsoft.sqlserver.jdbc.SQLServerDriver" 
 url="jdbc:sqlserver://SANGKARAN;database=ILMU;" 
 user="*******" password="******"/>

<c:set var="empId" value="102"/>

<sql:update dataSource="${snapshot}" var="count">
 UPDATE Employees SET last VALUES = 'Ali'
 <sql:param value="${empId}" />
</sql:update>

This is the error

org.apache.jasper.JasperException: javax.servlet.ServletException: javax.servlet.jsp.JspException:

UPDATE Employees SET last VALUES = 'Ali'

The index 1 is out of range. org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:548) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:454) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340) javax.servlet.http.HttpServlet.service(HttpServlet.java:725) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

root cause

com.microsoft.sqlserver.jdbc.SQLServerException: The index 1 is out of range. com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(Unknown Source) com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.setterGetParam(Unknown Source) com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.setObject(Unknown Source) org.apache.taglibs.standard.tag.common.sql.UpdateTagSupport.setParameters(UpdateTagSupport.java:262) org.apache.taglibs.standard.tag.common.sql.UpdateTagSupport.doEndTag(UpdateTagSupport.java:165) org.apache.jsp.updatetest_jsp._jspx_meth_sql_005fupdate_005f0(updatetest_jsp.java:274) org.apache.jsp.updatetest_jsp._jspService(updatetest_jsp.java:145) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) javax.servlet.http.HttpServlet.service(HttpServlet.java:725) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:431) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340) javax.servlet.http.HttpServlet.service(HttpServlet.java:725) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

I could really use some help.

1
Can you post the code which is running on the backend?mjuarez
The code is up there where i said " This is the code snippet" (the one in red and blue color). This is the code there is nothing else. These are inserted in normal html codes to make jsp pages. (the one in red and blue color) Thanks for helping out bro!Sangkaran
Is it because you are providing a parameter value when the SQL statement has no parameters?Turophile
I'm sorry, i don't really get it. Could you explain a little bit more in details? Thanks!Sangkaran
It's ok apparently i just have to change my query a little bit and the param.Sangkaran

1 Answers

0
votes

It's ok i have figured it out. My syntax for the queries and param was wrong. All i had to do was change it like this and it works.

<sql:update dataSource="${snapshot}" var="count">
UPDATE Employees SET last = ?
            WHERE id='${empId}'
<sql:param value="${lastname}" />
</sql:update>

That was all. I hope this helps someone who is experiencing the same problem. Thank you!