Selenium: db and excel data into maps

package learning;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.TreeMap;

import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import com.codoid.products.exception.FilloException;
import com.codoid.products.fillo.Connection;
import com.codoid.products.fillo.Fillo;
import com.codoid.products.fillo.Recordset;

public class uploadFileinMap {
@SuppressWarnings("resource")
public static void main(String[] args) throws IOException, FilloException, ClassNotFoundException, SQLException {
excelINTO_TreeMap();
db_INTO_HashMap();

}

public static void db_INTO_HashMap() throws FilloException, SQLException, ClassNotFoundException
{
String sQuery="Select defectid from qedge.dms";
String dbUrl = "jdbc:mysql://localhost:3306/qedge";
String username = "root";
String password = "sasa";
Class.forName("com.mysql.cj.jdbc.Driver");
java.sql.Connection con = DriverManager.getConnection(dbUrl, username, password);
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(sQuery);
List> resultlist = new ArrayList>();
Maprow=null;

        ResultSetMetaData meta = rs.getMetaData();
        int ColumnCount=meta.getColumnCount();
       
        while (rs.next()) {
        row= new HashMap();       
            for (int i = 1; i <= ColumnCount; i++)
            {
                row.put(meta.getColumnName(i), rs.getObject(i));
            }
            resultlist.add(row);
           
        }
        for (Map map:resultlist){
        for (String key : map.keySet())
            {
//        System.out.println(key);
//            System.out.println(map.get(key).toString());
            System.out.println(map.get("defectid").toString());
           
            }
        }

 
}

public static void excelINTO_TreeMap() throws FilloException
{
String filePath="D:\\Selenium\\TestDataUpload.xlsx";
String Sheetname ="Sheet1";
TreeMap> resultList = new TreeMap>();
TreeMap resetset = new TreeMap();
String sQuery="Select * from Sheet1";
ArrayList a;

Fillo fileo=new Fillo();
Connection con = fileo.getConnection(filePath);
Recordset rs = con.executeQuery(sQuery);

while (rs.next()) {
TreeMap innermap =new TreeMap();
a=rs.getFieldNames();
for (int k=0;k {

innermap.put(a.get(k).toString(),rs.getField(a.get(k).toString()));
resultList.put(rs.getField(a.get(0).toString()), innermap);
resetset.put(rs.getField(a.get(0).toString()), rs.getField(a.get(1).toString()));
}

}
for (Entry entry:resetset.entrySet())
{
String value1=((TreeMap)resultList.get(entry.getKey())).get("R1C1");
System.out.println("printing from loop 1 ----" + value1);
}
}


}

Comments

Popular posts from this blog

Test Batch Runner - Run QTP Scripts from xls file

Python: get entire workbook data cell by cell