Combo Box Filler via SelectItems (Java and CSV File)


	
	@SuppressWarnings("null")
	//begin comboList Items grab
	public List<SelectItem> getSelectItems() throws IOException {

		//set up empty placeholder list Items
		List<SelectItem> selectItems = new ArrayList<SelectItem>();

		  //...
		  //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: use Prepared Statement here...
	      Statement stmt = conn.createStatement();

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

	      // dump out the results
	      while (results.next())
	      {
	    	  
	    	  //TO DO: Write additional code to build results Xpages form onBeforeP{ageLoad
		    ComboVariableName = results.getString("ColumnInCSV");
	    	
	    	//Load to Console as test
	        //System.out.println("||  "+"ComboVariableName " +"||"+ " ComboVariableName "+" ||");
	        //System.out.println("||  "+ ComboVariableName + "                 || " + ComboVariableName +"         ||");
	        
	      //load resutlset into selection comboList
			selectItems.add(new SelectItem(ComboVariableName.toString()));
	        
	      }

	      // clean up
	      results.close();
	      stmt.close();
	      conn.close();
	    }
	    catch(Exception e)
	    {
	      e.printStackTrace();
	    }	
		//List ColumnInCSV results found
		return selectItems;
	}
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...