title: Exporting resultset
body: <p>I'm very new to Java and am looking for some assistance.  I have a resultset that I'm able to either print (without titles, but that's for a different time), or can produce a jtable.</p>
  
  <p>Ultimately, though, I want to be able to send it to excel.  I don't really care whether it is a CSV or XLS, I just want to be able to get it to Excel.</p>
  
  <p>I downloaded OpenCSV and have it added to the build path, but I still can't get it to work.  I've even tried forklifting multiple different version of code, but nothing still works.  I have the code below.</p>
  
  <pre><code>import java.io.IOException;
  import java.sql.Connection;
  import java.sql.ResultSet;
  import java.sql.ResultSetMetaData;
  import java.sql.SQLException;
  import java.sql.Statement;
  
  import javax.swing.JTable;
  import java.math.BigDecimal;
  import java.sql.Date;
  import java.sql.Time;
  import java.sql.Timestamp;
  import java.text.ParseException;
  import java.util.ArrayList;
  import java.util.regex.Pattern;
  import java.io.*;
  
  
  public class RuneDW {
  
  
      public static void main(String[] args) throws SQLException, IOException {
  
          Connection conn = null;
          Statement stmt = null;
          ResultSet rs = null;
          JTable table = null;
          File file = File.createTempFile("test",".csv");
  
          try {
  
              conn = DBUtil.getConnected(DBType.EDW);
              stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
              rs = stmt.executeQuery("select trunc(acct_d) as acct_d, cust_ord_i, sls_q from fin_sls where rownum&lt;=13" +
                      "and acct_d&gt;= sysdate-2");
              ArrayList&lt;String&gt; arrayList = new ArrayList&lt;String&gt;();
              ResultSetMetaData metadata = rs.getMetaData();
              int numberOfColumns = metadata.getColumnCount();
              while (rs.next()) {              
                  int i = 1;
                  while(i &lt;= numberOfColumns) {
                      arrayList.add(rs.getString(i++));
                  }
                  System.out.println(rs.getString("acct_d")+rs.getString("cust_ord_i")+rs.getString("sls_q"));
  
          }
          } finally {
          }
  
          }
      }
  </code></pre>