title: How to print string value out of while loop?
body: <p>Hi I am trying to fetch value from database and print that all value on console. when I print value inside the while loop its work and give all value as a string but when I try to print all value out of while loop it gives me only last value how can I get all value out of loop as a string</p>
  
  <p>Here is my code</p>
  
  <pre><code>import java.sql.*;
  public class commoditywise {
      public static void main(String args[])
      {
          String s=null;
          String id = "paddy";
          String driverName = "com.mysql.jdbc.Driver";
          String connectionUrl = "jdbc:mysql://localhost:3306/";
          String dbName = "mandi";
          String userId = "root";
          String password = "";
          String market=null;
          String rate=null;
          try {
              Class.forName(driverName);
          } catch (ClassNotFoundException e) {
              e.printStackTrace();
          }
  
          Connection connection = null;
          Statement statement = null;
          ResultSet resultSet = null;
  
          try{ 
              connection = DriverManager.getConnection(connectionUrl+dbName, userId, password);
              statement=connection.createStatement();
              String sql = "select ch.mandihindi,cw.price from commoditywise cw inner join mandihindi ch on ch.mandieng=cw.mandi where cw.commodity=  '"+id+"'";
  
              resultSet = statement.executeQuery(sql);
              while(resultSet.next()){
                  market=resultSet.getString("mandihindi");
                  rate=resultSet.getString("price");
  
                  market=market.concat("~");
                  rate=rate.concat("|");
  
                  s=market.concat(rate);
                  s=s.replaceAll(" ", "");
              }
              System.out.println(s);
          }
  
          catch (Exception e) {
              e.printStackTrace();
          }
      }
  }
  </code></pre>
  
  <p>How can I get my desired out put?</p>