Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Validations like:
- 1. The cell data should be only numeric
- 2. The cell data should be in a specific format xxx-xxx
- 3. The cell data should be a date in yyyy-mm-dd format
- > package src;
- >
- > import java.io.FileInputStream; import java.io.IOException; import
- > java.sql.Connection; import java.sql.DriverManager; import
- > java.sql.PreparedStatement; import
- > org.apache.poi.poifs.filesystem.POIFSFileSystem; //import
- > org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.*;
- >
- > import org.apache.poi.xssf.usermodel.XSSFWorkbook; import
- > org.apache.poi.xssf.usermodel.XSSFSheet;
- >
- > public class DataKauai {
- >
- > public static void main(String[] args) throws Exception {
- >
- > try {
- >
- > Class forName = Class.forName("com.sybase.jdbc2.jdbc.SybDriver");
- > Connection con = null;
- > con = DriverManager.getConnection("jdbc:sybase:Tds:tkbgssvt1:4105",
- > "kauai_rwu","rwu_kauai");
- > System.out.println("Database connected to Sybase..");
- > con.setAutoCommit(false);
- > PreparedStatement pstm = null;
- > FileInputStream input = new FileInputStream("C:\Users\suresnar\Desktop\Mizu_FGloss\Kauai_IN_Table_test.xlsx");
- > // POIFSFileSystem fs = new POIFSFileSystem(input);
- >
- > XSSFWorkbook workbook = new XSSFWorkbook(input);
- > XSSFSheet sheet = workbook.getSheetAt(0);
- > Row row;
- > for (int i = 1; i <= sheet.getLastRowNum(); i++) {
- > row = (Row) sheet.getRow(i);
- > DataFormatter formatter = new DataFormatter();
- > String TradeAction = formatter.formatCellValue(row.getCell(0));
- > String TradeID = formatter.formatCellValue(row.getCell(1));
- > String Version =formatter.formatCellValue(row.getCell(2));
- > String TradeType = formatter.formatCellValue(row.getCell(3));
- > String Book = formatter.formatCellValue(row.getCell(4));
- > String Direction = row.getCell(5).getStringCellValue();
- > String SafekeepFlag = row.getCell(6).getStringCellValue();
- > String OurSettlePlace = formatter.formatCellValue(row.getCell(7));
- > String OurSettleDepot = row.getCell(8).getStringCellValue();
- > String TheirSettlePlace = row.getCell(9).getStringCellValue();
- > String TheirSettleDepot = row.getCell(10).getStringCellValue();
- > String BrokerCode = row.getCell(11).getStringCellValue();
- > String CustomerCode =formatter.formatCellValue(row.getCell(12));
- > String ProductCode = formatter.formatCellValue(row.getCell(13));
- > String TradeDate =formatter.formatCellValue(row.getCell(14));
- > String TradeTime = formatter.formatCellValue(row.getCell(15));
- > String CreditPerson = row.getCell(16).getStringCellValue();
- > String Quantity = formatter.formatCellValue(row.getCell(17));
- > String Factor = formatter.formatCellValue(row.getCell(18));
- > String ActualQuantity = formatter.formatCellValue(row.getCell(19));
- > String SettleDate = formatter.formatCellValue(row.getCell(20));
- > String Price = formatter.formatCellValue(row.getCell(21));
- > String TradeCcy = row.getCell(22).getStringCellValue();
- > String TradeValue = formatter.formatCellValue(row.getCell(23));
- > String AccDays = formatter.formatCellValue(row.getCell(24));
- > String TradeAICcy = formatter.formatCellValue(row.getCell(25));
- > String TradeAI = formatter.formatCellValue(row.getCell(26));
- > String SettleAmt = formatter.formatCellValue(row.getCell(27));
- > String RateCalc = formatter.formatCellValue(row.getCell(28));
- > String FxRate = formatter.formatCellValue(row.getCell(29));
- > String SettleCcy = formatter.formatCellValue(row.getCell(30));
- > String SettleAmtInFX = formatter.formatCellValue(row.getCell(31));
- > String Memo1 = row.getCell(32).getStringCellValue();
- > String Memo2 = row.getCell(33).getStringCellValue();
- > String Memo3 = row.getCell(34).getStringCellValue();
- > String Memo4 = row.getCell(35).getStringCellValue();
- > String Memo5 = row.getCell(36).getStringCellValue();
- > String Remark1 = row.getCell(37).getStringCellValue();
- > String Remark2 = row.getCell(38).getStringCellValue();
- > String SelfStBrCode = formatter.formatCellValue(row.getCell(39));
- > String SelfStBrSubCode = formatter.formatCellValue(row.getCell(40));
- > String CustStBrCode = formatter.formatCellValue(row.getCell(41));
- > String CustStClCode = formatter.formatCellValue(row.getCell(42));
- > String CustStSubCode = formatter.formatCellValue(row.getCell(43));
- > String DiscretionFlg = formatter.formatCellValue(row.getCell(44));
- > String InputTime = formatter.formatCellValue(row.getCell(45));
- > String UpdateTime = formatter.formatCellValue(row.getCell(46));
- > String IFStatus = formatter.formatCellValue(row.getCell(47));
- > String IFVersion = formatter.formatCellValue(row.getCell(48));
- > String IFDate = formatter.formatCellValue(row.getCell(49));
- > String IFTime = formatter.formatCellValue(row.getCell(50));
- > String AzIFStatus = formatter.formatCellValue(row.getCell(51));
- > String AzIFVersion =formatter.formatCellValue(row.getCell(52));
- > String AzIFTime =formatter.formatCellValue(row.getCell(53));
- > String AzCKTime =formatter.formatCellValue(row.getCell(54));
- >
- >
- >
- > // String email = row.getCell(3).getStringCellValue();
- >
- > if(IFTime==" ")
- > {
- > if(IFVersion==" ")
- > {
- > if(IFDate==" ")
- > {
- > if(IFStatus==" ")
- > {
- > if(TradeID.length()==14)
- > {
- >
- > if(TradeDate>=SettleDate)
- > {
- >
- >
- > String sql = "INSERT INTO FB_KAUAI_IN (TradeAction,TradeID,Version,TradeType,Book,Direction,SafekeepFlag,OurSettlePlace,"
- > + "OurSettleDepot,TheirSettlePlace,TheirSettleDepot,BrokerCode,"
- > + "CustomerCode,ProductCode,TradeDate,TradeTime,CreditPerson,Quantity,Factor,"
- > + "ActualQuantity,SettleDate,Price,TradeCcy,TradeValue,AccDays,TradeAICcy,"
- > + "TradeAI,SettleAmt,RateCalc,FxRate,SettleCcy,SettleAmtInFX,Memo1, Memo2, "
- > + "Memo3, Memo4, Memo5, Remark1, Remark2 ,SelfStBrCode, SelfStBrSubCode, "
- > + "CustStBrCode, CustStClCode, CustStSubCode, DiscretionFlg, InputTime, "
- > + "UpdateTime, IFStatus, IFVersion, IFDate, IFTime, AzIFStatus, "
- > + "AzIFVersion,AzIFTime,AzCKTime) VALUES('"+TradeAction+"','"+TradeID+"','"+Version+"', "
- > + "'"+TradeType+"','"+Book+"','"+Direction+"','"+SafekeepFlag+"',"
- > + "'"+OurSettlePlace+"','"+OurSettleDepot+"','"+TheirSettlePlace+"',"
- > + "'"+TheirSettleDepot+"','"+BrokerCode+"','"+CustomerCode+"','"+ProductCode+"',"
- > + "'"+TradeDate+"','"+TradeTime+"','"+CreditPerson+"','"+Quantity+"','"+Factor+"',"
- > + "'"+ActualQuantity+"','"+SettleDate+"','"+Price+"','"+TradeCcy+"',"
- > + "'"+TradeValue+"','"+AccDays+"','"+TradeAICcy+"','"+TradeAI+"','"+SettleAmt+"',"
- > + "'"+ RateCalc+"','"+FxRate+"','"+SettleCcy+"','"+SettleAmtInFX+"','"+Memo1+"',"
- > + "'"+Memo2+"','"+Memo3+"','"+Memo4+"','"+Memo5+"','"+Remark1+"','"+Remark2+"',"
- > + "'"+SelfStBrCode+"','"+SelfStBrSubCode+"','"+CustStBrCode+"','"+CustStClCode+"',"
- > + "'"+CustStSubCode+"','"+DiscretionFlg+"','"+InputTime+"','"+UpdateTime+"',"
- > + "'"+IFStatus+"','"+IFVersion+"','"+IFDate+"','"+IFTime+"',"
- > + "'"+AzIFStatus+"','"+AzIFVersion+"','"+AzIFTime+"',"
- > + "'"+AzCKTime+"')";
- >
- >
- >
- > //System.out.println("results " +sql);
- > pstm = (PreparedStatement) con.prepareStatement(sql);
- > pstm.execute();
- > System.out.println("Imported rows " + i);
- >
- > }
- > else System.out.println("IFStatus not null");
- > }
- > else
- > System.out.println("IFDate is not null");
- > }
- > else
- > System.out.println("IFVersion is not null");
- > }
- > else
- > System.out.println("IFTime is null");
- > }
- > else
- > System.out.println("TradeID is not 14 letters");
- > }
- > else
- > System.out.println("Settele date is more than Trade ID");
- >
- > con.commit();
- > pstm.close();
- > con.close();
- > input.close();
- > System.out.println("Success import excel to mysql table");
- >
- >
- > }
- >
- > }
- > catch (IOException e) {
- > e.printStackTrace();
- > }
- > catch(Exception e){
- > //Handle errors for Class.forName
- > e.printStackTrace();
- > }
- > } }
Add Comment
Please, Sign In to add comment