Query CSV File from Java - Backing Bean


/**
 * Created: 2012.04.21.5.56.PM
 * Build Results into Console with CSV
 */
package com.dokoll.solutions.inc.cvs.trials;

/**
 * @author Dököll Solutions, Inc.
 * @version 2012.04.21.5.56.PM
 *
 */
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

//...
//Start of Program
public class ReadCSVFileBean
{
	
	//...
	//Button code
  public static void doGetCSVConsoleData()
  {
	  //...
	  //Entering try catch
    try
    {
      // load the driver into memory
      Class.forName("org.relique.jdbc.csv.CsvDriver");

      // create a connection. The first command line parameter is assumed to
      //  be the directory in which the .csv files are held
      Connection conn = DriverManager.getConnection("jdbc:relique:csv:C:\\temp\\CSV_DATA\\");

      // create a Statement object to execute the query with
      //2012.04.21.6.02.PM
      //TO DO: Attempt using Prepared Statement here...
      Statement stmt = conn.createStatement();

      // Select* from UserNewLineOutboundInformation.csv
      ResultSet results = stmt.executeQuery("SELECT * FROM UserNewLineOutboundInformation");

      // dump out the results
      while (results.next())
      {
    	  
    	  //TO DO: Write a separate JavaBean to build setters for variables
    	  //that can used in Xpages...
    	String SiteName = results.getString("SiteName");
    	String SiteNumber = results.getString("SiteNumber");
    	//Load to Console
        System.out.println("SiteName " + " SiteNumber");
        System.out.println(SiteName + " " + SiteNumber);
      }

      // clean up
      results.close();
      stmt.close();
      conn.close();
    }
    catch(Exception e)
    {
      e.printStackTrace();
    }
  }//end of program...
  
  
}
All code submitted to OpenNTF XSnippets, whether submitted as a "Snippet" or in the body of a Comment, is provided under the Apache License Version 2.0. See Terms of Use for full details.
No comments yetLogin first to comment...