0 Replies - 301 Views - Last Post: 15 June 2014 - 10:21 AM Rate Topic: -----

#1 Dnamonk  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 15-June 14

variable Lists and sql statement : JSTL - Mysql troubles

Posted 15 June 2014 - 10:21 AM

Hello everyone,

I am new to this site and I have a question which is troubling me.

Let me describe.
1- I am reading a file.
2- Then I am assigning the list values via request.setAttribute.
3 - Finally I am using JSTL sql:query Tag to use select statement to query the database.
4- I am using a foreach lope inside the sql:query tag to browse through the list.
5- The problem is that I am only getting the search result when I have only 1 line in my file OR else I am getting a silly error.

Here is my code
<%
       ArrayList schoolarraylist = new ArrayList();
%>
<% 
    String fName = "Path/filename.txt";
    String thisLine; 
    int count=0; 
    FileInputStream fis = new FileInputStream(fName);
    DataInputStream myInput = new DataInputStream(fis);
    int i=0; 
%>

<%
    while ((thisLine = myInput.readLine()) != null)
   {
    String myVariable = thisLine;

    out.println(myVariable);

    schoolarraylist.add(myVariable);

    //request.getSession().setAttribute("myVariable", myVariable);

    } 
        request.setAttribute("schoolarraylist", schoolarraylist);
%>
<jsp:useBean id="mybean" scope="page" class="Access_Codes" />
<jsp:setProperty name="mybean" property="*" />

<sql:query var="row" dataSource="jdbc/mydatabase">
    <c:forEach var="school" items="${schoolarraylist}">
                 select * from myTable where valueInFile = "<c:out value='${school}'/>";
    </c:forEach>     
</sql:query>
              



This is the Error I am getting


javax.servlet.ServletException: 
    
                 select * from myTable where valueInFile = "06985";
    
                 select * from myTable where valueInFile = "06986";
         
: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'select * from myTable where valueInFile = "06986"' at line 3
	at org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:944)
	at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:879)
	at org.apache.jsp.FILE_005f1_jsp._jspService(FILE_005f1_jsp.java:149)
	at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:770)
	at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:411)
	at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:473)
	at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:377)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:770)
	at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1550)
	at org.apache.catalina.core.ApplicationDispatcher.doInvoke(ApplicationDispatcher.java:809)
	at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:671)
	at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:505)
	at org.apache.catalina.core.ApplicationDispatcher.doDispatch(ApplicationDispatcher.java:476)
	at org.apache.catalina.core.ApplicationDispatcher.dispatch(ApplicationDispatcher.java:355)
	at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:305)
	at com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:546)
	at com.sun.faces.application.view.JspViewHandlingStrategy.executePageToBuildView(JspViewHandlingStrategy.java:364)
	at com.sun.faces.application.view.JspViewHandlingStrategy.buildView(JspViewHandlingStrategy.java:154)
	at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:100)
	at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
	at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
	at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
	at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1550)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
	at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
	at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
	at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
	at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
	at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
	at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)
	at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)
	at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)
	at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)
	at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
	at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
	at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
	at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
	at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
	at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
	at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
	at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
	at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
	at java.lang.Thread.run(Thread.java:744)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'select * from myTable where valueInFile = "06986"' at line 3
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
	at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
	at com.mysql.jdbc.Util.getInstance(Util.java:386)
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1052)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3609)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3541)
	at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2002)
	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2163)
	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2624)
	at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2127)
	at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2293)
	at org.apache.taglibs.standard.tag.common.sql.QueryTagSupport.doEndTag(QueryTagSupport.java:257)
	at org.apache.jsp.FILE_005f1_jsp._jspx_meth_sql_query_0(FILE_005f1_jsp.java:191)
	at org.apache.jsp.FILE_005f1_jsp._jspService(FILE_005f1_jsp.java:124)
	... 44 more




I would appreciate if someone Guru here can guide me the soultion.

Thank you in advance for the help and advice.

Cheers
Dnamonk

Is This A Good Question/Topic? 0
  • +

Page 1 of 1