title: SQL statement is not executed! java.sql.SQLException: General error
body: <p>So, my piece of code is giving "SQL statement is not executed! </p>
  
  <blockquote>
    <p>java.sql.SQLException: General error" </p>
  </blockquote>
  
  <p>Probably it is due to this line-"ResultSet rs = st.executeQuery(sqlq);" in my code.  What could be the possible reason to it and how can it be corrected ? please help !</p>
  
  <pre><code>//package searchbook;
  import java.io.*;
  import javax.servlet.*;
  import javax.servlet.http.*;
  import java.sql.*;
  import java.util.*;
  
  public class SearchBook extends HttpServlet {
  public void doPost(HttpServletRequest request, HttpServletResponse response)
  throws ServletException,IOException{
  response.setContentType("text/html"); 
  HttpSession session = request.getSession(true);
  List booklist=new ArrayList();
  Connection con = null;
  
  String url = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=" + "C:\\users\\ppreeti\\executive_db.accdb";
  
  String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
  String user = "";
  String pass = "";
  String category="";
  category=request.getParameter("input");
  String sqlquery="select   Index1.link_id "    
          + "FROM Index1 "
          + " WHERE  Index1.index_name LIKE '%"+category+"%'  ";
  String sqlResult = null;
  try
      {
          Class.forName(driver);
          con = DriverManager.getConnection(url, user, pass);
              try{
                  Statement st = con.createStatement();
                  System.out.println("Connection created 1");
                  ResultSet rs = st.executeQuery(sqlquery);
                  while (rs.next())
                  {
                  sqlResult = rs.getString(1);
  
                  }
                  System.out.println("Result retreived  1");
                  //System.out.println('"sqlquery"');
              }
              catch (SQLException s)
              {
                  System.out.println("SQL statement is not executed! "+ s);
              }
          }
      catch (Exception e){
          e.printStackTrace();
      }
  System.out.println("************");
  //String sqlq="";
  
  if(sqlResult.equals("1"))
  {
  String sqlq="select Section.Section_Name , Report.Report_Name , Report.Link, Contact.Contact_Name, Metrics.Metric_Name "
          + "FROM Section , Report , Contact,Metrics "
          + "WHERE Report.Contact_ID=Contact.Contact_ID and Report.Section_ID=Section.Section_ID  "
          + "and Report.Report_ID IN (SELECT Metrics.Report_ID FROM Metrics  WHERE Metrics.Metric_Name = Report.Report_ID') and Metrics.Metric_Segment = 'M' ";
  
  System.out.println("2nd query executed too !");
  try
  {
      Class.forName(driver);
      con = DriverManager.getConnection(url, user, pass);
          try
              {
              Statement st = con.createStatement();
              System.out.println("Connection created");
              ResultSet rs = st.executeQuery(sqlq);
              System.out.println("Result retreived  ");
              while (rs.next())
              {
              List&lt;String&gt; book=new ArrayList&lt;String&gt;();
  
              String Name=rs.getString("Section_Name");
              String reportName=rs.getString("Report_Name");
              String link=rs.getString("Link");
              String contactName=rs.getString("Contact_Name");
              String metricName=rs.getString("Metric_Name");
              //String reportId=rs.getString("Report_ID");
  
              /*String ind_id=rs.getString("index_name");
              String ind_name=rs.getString("link_id");*/
  
              book.add(Name);
              book.add(reportName);
              book.add(link);
              book.add(contactName);
              book.add(metricName);
              //book.add(reportId);
  
              /*book.add(ind_id);
              book.add(ind_name);*/
  
              booklist.add(book);
              }
          }
          catch (SQLException s)
          {
              System.out.println("SQL statement is not executed! "+ s);
          }
      }
  catch (Exception e) {
  e.printStackTrace();
  }}
  System.out.println("And it came here lastly !");
  request.setAttribute("booklist",booklist); 
  RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/searchbook.jsp");
  dispatcher.forward(request, response); 
  }
  }
  </code></pre>
  
  <p>And the output in Eclipse console as:</p>
  
  <pre><code>   Connection created 1 Result retreived 1 ************ 2nd query executed too ! Connection created SQL statement is not executed! java.sql.SQLException:: General error And it came here lastly !
  </code></pre>