Query CSV File from Java - Backing Bean

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

 * @author Dököll Solutions, Inc.
 * @version 2012.
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
      // load the driver into memory

      // 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
      //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
    catch(Exception e)
  }//end of program...

Query CSV file into Java Application, add results to console.  To be honest, not too much testing on this one, play around with it, see what else you can do...  Will not post an Xpage this time, you can add under a button/link as you wish.  

Note: If you build a JavaAgent, you will not need the jdbc jar file, but from Project Explorer, you need the jar in the CLASSPATH, and it should be referenced via build path...  Also seems to work well having the jar in the /lib/ext directory in Notes.

Köll S Cherizard
April 21, 2012 7:41 PM

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...