How to download data as csv from database using java?
<p>I need to download the csv file from database using database.</p>

<p>I have jdbc connection and execute the query , get the data from database.Those values are download as csv format using java class.</p>

<pre><code>Java class:
String filename="Cases.csv";
//here database connection.


ResultSet rst= stmt.executeQuery(qry);
    System.out.println("1"+rst);
    if(rst.next())
    {

    Content=rst.getString("USER_details");

    }
    //ServletOutputStream out = null;
    //out.println(Content);
    System.out.println("1"+Content);
    byte requestBytes[] = Content.getBytes();
    ByteArrayInputStream bis = new ByteArrayInputStream(requestBytes);
    response.reset();
    response.setContentType("application/text");
    response.setHeader("Content-disposition","attachment; filename=" +filename);
    byte[] buf = new byte[1024];
    int len;
    while ((len = bis.read(buf)) &gt; 0){
    response.getOutputStream().write(buf, 0, len);
    }
    bis.close();
    response.getOutputStream().flush(); 
    }
    catch(Exception e){
    e.printStackTrace();
    }
</code></pre>

<p>How to get all values from database to csv format ?</p>
