title: How to convert SQL query to JSON Array
body: <p>i need to convert the result of a query like this:</p>
  
  <pre><code>SELECT * FROM table WHERE column1=X
  </code></pre>
  
  <p>to a JSONArray in java.
  In my table i have the following columns</p>
  
  <ol>
  <li>id: int PRIMARY KEY AUTO_INCREMENT</li>
  <li>string</li>
  <li>string</li>
  <li>string</li>
  <li>string</li>
  <li>string</li>
  <li>int</li>
  <li>timeStamp CURRENT_TIMESTAMP</li>
  </ol>
  
  <p>I need to maintain the same structure except the id field that i don't need.</p>
  
  <pre><code>public static ArrayList&lt;Ticket&gt; lookForATicket(String fermataDiscesa) throws Exception {
      Connection dbConn = null;
      ArrayList&lt;Ticket&gt; list = null;
      try {
          try {
              dbConn = DBConnection.createConnection();
          } catch (Exception e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
          Statement stmt = dbConn.createStatement();
          String query = "SELECT * FROM offer WHERE fermataDiscesa = '" + fermataDiscesa
                  + "'";
          //test
          System.out.println(query);
          ResultSet rs = stmt.executeQuery(query);
          list = new ArrayList&lt;Ticket&gt;();
          Ticket tickets = null;
          while (rs.next()) {
              //per test
              System.out.println(rs.getString(1) + rs.getString(2) + rs.getString(3) + rs.getString(4) + rs.getString(5) + rs.getString(6) + rs.getInt(7));
              tickets = new Ticket();
              //setto i campi
              tickets.setIdGooglePlus(rs.getString("IDGOOGLEPLUS"));
              tickets.setIdFacebook(rs.getString("IDFACEBOOK"));
              tickets.setFermataSalita(rs.getString("FERMATASALITA"));
              tickets.setFermataDiscesa(rs.getString("FERMATADISCESA"));
              tickets.setBus(rs.getString("BUS"));
              tickets.setTempoRimasto(rs.getInt("TEMPORIMASTO"));
              tickets.setTimeStamp(rs.getTimestamp("TIMESTAMP"));
              //aggiungo alla lista
              list.add(tickets);
          }
      } catch (SQLException sqle) {
          throw sqle;
      } catch (Exception e) {
          // TODO Auto-generated catch block
          if (dbConn != null) {
              dbConn.close();
          }
          throw e;
      } finally {
          if (dbConn != null) {
              dbConn.close();
          }
      }
      return list;
  }
  </code></pre>
  
  <p>Ticket is my custom class.
  And that is the code for "printing" my JSON object:</p>
  
  <pre><code>    //Path: http://localhost:8080/RESTscambio/search
  @Path("/search")
  public class Search {
      // HTTP Get Method
      @GET 
      // Path: http://localhost:8080/RESTscambio/search/dosearch
      @Path("/dosearch")
      // Produces JSON as response
      @Produces(MediaType.APPLICATION_JSON) 
  
  public String doSearch(@QueryParam("fermataDiscesa") String fermataDiscesa) throws Exception{
      System.out.println("Cerco biglietti..");
      ArrayList&lt;Ticket&gt; list = null;
      String response = null;
  
      list = DBConnection.lookForATicket(fermataDiscesa);
      JSONArray jArray = new JSONArray(list);
  
      if(list != null){
          //System.out.println(jObj.put("list_of_ticket", list).toString());
          //jObj.put("list_of_ticket", list);
          response = Utility.constructJSON("Biglietti disponibili", true);
      }else{
          response = Utility.constructJSON("Nessun biglietto disponibile", false);
      }
  return response;        
  }
  </code></pre>
  
  <p>I need to use response. I can define a new function to print. Can someone help me?
  Thank you </p>