CsvReader products = new CsvReader("products.csv"); products.readHeaders(); while (products.readRecord()) { String productID = products.get("ProductID"); String productName = products.get("ProductName"); String supplierID = products.get("SupplierID"); String categoryID = products.get("CategoryID"); String quantityPerUnit = products.get("QuantityPerUnit"); String unitPrice = products.get("UnitPrice"); String unitsInStock = products.get("UnitsInStock"); String unitsOnOrder = products.get("UnitsOnOrder"); String reorderLevel = products.get("ReorderLevel"); String discontinued = products.get("Discontinued"); // perform program logic here System.out.println(productID + ":" + productName); } products.close();
import com.csvreader.CsvReader; class Parser { public static void main (String [] args) throws Throwable { CsvReader reader = new CsvReader("input file name.csv", ',' /* delimiter */ ); while (reader.readRecord()) { // full row, you can use regex to find // any rows you specifically want String row = reader.getRawRecord(); // get value of the first field String col = reader.get(0); // gets array of fields String[] cols[] = reader.getValues(); } reader.close(); } }
String Valid = products.get(s[x]); row.addAll(Valid);
CsvReader products = new CsvReader("sample.csv"); products.readHeaders(); while (products.readRecord()) { String productID = products.get("field1"); String productName = products.get("field2"); String supplierID = products.get("field3"); String categoryID = products.get("field4"); } products.close();
String productID = products.get("ProductID"); String productName = products.get("ProductName"); String supplierID = products.get("SupplierID"); String categoryID = products.get("CategoryID"); String quantityPerUnit = products.get("QuantityPerUnit"); String unitPrice = products.get("UnitPrice"); String unitsInStock = products.get("UnitsInStock"); String unitsOnOrder = products.get("UnitsOnOrder"); String reorderLevel = products.get("ReorderLevel"); String discontinued = products.get("Discontinued");
CsvReader products = new CsvReader("/tmp/ip2location/IP-COUNTRY-REGION-CITY-LATITUDE-LONGITUDE-ISP-DOMAIN-MOBILE-USAGETYPE.CSV"); products.readHeaders(); while (products.readRecord()) { String ip_from = products.get("ip_from"); //int String ip_to = products.get("ip_to"); //int PreparedStatement prepareStat = null; String sqlIinsert = "insert into ip2location_tmp(ip_from, ip_to )" + " VALUES ("+ip_from+","+ip_to+");"; System.out.println("sqlInsert:"+sqlIinsert); prepareStat = conn.prepareStatement(sqlIinsert); prepareStat.executeUpdate(); } products.close(); }enter code here
public String getValue(String fileName, String rowNum, int colHeader) { String returnVal = null; String relativePath = System.getProperty("user.dir"); String csvPath = relativePath + "\\src\\main\\resources\\CSV\\" + fileName + ".csv" ; CsvReader r; try { r = new CsvReader(csvPath); while(r.readRecord()) { String row = r.get(0); if(row.equalsIgnoreCase(rowNum) ) { returnVal = r.get(colHeader); break; } } r.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return returnVal; }
reader.readHeaders(); while (reader.readRecord()) { map.put(reader.get("RollNo"), new ListMap(reader.get("RollNo"), reader.get("Name"), reader.get("Class"), reader.get("City"), reader.get("Town"))); ListMap obj = map.get(reader.get("RollNo")); if (obj != null) { obj.setCity(reader.get("City")); obj.setTown(reader.get("Town")); } else { obj = new ListMap(reader.get("RollNo"), reader.get("Name"), reader.get("Class"), reader.get("City"), reader .get("Town")); map.put(reader.get("RollNo"), obj);