Commit 68f14b75 authored by kevinjdk's avatar kevinjdk

Proyecto

Proyecto Nomina-Rubros
parent a89d1cca
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
#Mon Sep 09 09:26:12 COT 2019
gradle.version=5.4
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>SpringFileUploadToDB</name>
<comment>Project SpringFileUploadToDB created by Buildship.</comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.common.project.facet.core.builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.validation.validationbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.springframework.ide.eclipse.core.springbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.springframework.ide.eclipse.boot.validation.springbootbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.springframework.ide.eclipse.core.springnature</nature>
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
</natures>
</projectDescription>
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry excluding="**/bower_components/*|**/node_modules/*|**/*.min.js" kind="src" path="WebContent"/>
<classpathentry kind="src" path="target/m2e-wtp/web-resources"/>
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.WebProject">
<attributes>
<attribute name="hide" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.baseBrowserLibrary"/>
<classpathentry kind="output" path=""/>
</classpath>
connection.project.dir=
eclipse.preferences.version=1
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="springFileUpload-0.0.1-SNAPSHOT">
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
<wb-resource deploy-path="/" source-path="/WebContent" tag="defaultRootSource"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
<property name="context-root" value="springFileUpload"/>
<property name="java-output-path" value="/springFileUpload/target/classes"/>
</wb-module>
</project-modules>
<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
<fixed facet="wst.jsdt.web"/>
<installed facet="java" version="1.8"/>
<installed facet="jst.web" version="3.1"/>
<installed facet="wst.jsdt.web" version="1.0"/>
</faceted-project>
org.eclipse.wst.jsdt.launching.baseBrowserLibrary
\ No newline at end of file
disabled=06target
eclipse.preferences.version=1
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Talento Humano</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
</head>
<body>
<nav class="navbar navbar-dark bg-success">
<a class="navbar-brand">Universidad de las Fuerzas Armadas ESPE</a>
<ul class="navbar-nav mr-auto mt-2 mt-lg-0">
<li class="nav-item active">
<a class="nav-link" href="/springFileUpload/welcome">INICIO</a>
</li>
</nav>
<div class="card">
<h5 class="card-header">TALENTO HUMANO</h5>
<div class="card-body">
<h6 class="card-title">SELECCIONE EL ARCHIVO A SUBIR</h6>
<p class="card-text">
<form method="POST" action="${pageContext.request.contextPath}/upload" enctype="multipart/form-data" >
<div class="input-group mb-3">
<input type="file" name="file" class="form-control" placeholder="Recipient's username" aria-label="Recipient's username" aria-describedby="basic-addon2">
</div>
</p>
<h6 class="card-title">Estado de Carga</h6>
<p class="card-text">Mensaje : ${message}</p>
<input class="btn btn-primary" type="submit" value="Guardar" />
</form>
</div>
</div>
</body>
</html>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:security="http://www.springframework.org/schema/security"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">
<mvc:annotation-driven />
<context:component-scan base-package="com.learningsolo.spring*" />
<mvc:resources mapping="/resources/**" location="/resources/" />
<bean id="jspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
<!-- File Upload Configuration Bean Details -->
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize" value="1000000000" />
</bean>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="oracle.jdbc.OracleDriver" />
<property name="url" value="jdbc:oracle:thin:@localhost:1521/xe" />
<property name="username" value="kevin" />
<property name="password" value="pamela12kl" />
</bean>
<bean id="uploadService" class = "com.learningsolo.spring.FileUploadService" autowire="byType"></bean>
<bean id ="fileUploadDao" class = "com.learningsolo.spring.FileUploadDao" autowire="byType"></bean>
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
<display-name>SpringFileUpload</display-name>
<!-- <listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
-->
<servlet>
<servlet-name>springdispatcher_srr</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/springDispatcherContext.xml</param-value>
</init-param>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springdispatcher_srr</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
\ No newline at end of file
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.learningsolo.spring</groupId>
<artifactId>springFileUpload</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>FileUpload</name>
<description>FileUpload</description>
<properties>
<jdk.version>1.8</jdk.version>
<spring.version>4.3.7.RELEASE</spring.version>
<jstl.version>1.2</jstl.version>
<servletapi.version>3.1.0</servletapi.version>
<logback.version>1.1.3</logback.version>
<jcl.slf4j.version>1.7.12</jcl.slf4j.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>${jstl.version}</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.9</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.9</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml-schemas</artifactId>
<version>3.9</version>
</dependency>
<!-- compile only, deployed container will provide this -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>${servletapi.version}</version>
<scope>provided</scope>
</dependency>
<!-- Logging -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>${jcl.slf4j.version}</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
</configuration>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
package com.learningsolo.spring;
import javax.sql.DataSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
/**
* Abstract class BaseDAO
*/
public abstract class BaseDAO {
private DataSource dataSource = null;
private NamedParameterJdbcTemplate namedParamJdbcTemplate = null;
public DataSource getDataSource() {
return dataSource;
}
public void setDataSource(final DataSource dataSource) {
this.dataSource = dataSource;
if(namedParamJdbcTemplate == null) {
namedParamJdbcTemplate = new NamedParameterJdbcTemplate(dataSource);
}
}
public NamedParameterJdbcTemplate getNamedParamJdbcTemplate() {
return namedParamJdbcTemplate;
}
}
\ No newline at end of file
package com.learningsolo.spring;
public class ExcelTemplateVO {
private String PDRBDED_PIDM;
private String PDRBDED_BDCA_CODE;
private String PDRBDED_ADD_REPL_IND;
private String PDRBDED_ADD_REPL_EMPL;
private String PDRBDED_ADD_REPL_EMPR;
private String PDRBDED_ADD_REPL_TAX_BASE;
private String PDRBDED_ARR_STATUS;
private String PDRBDED_ARR_BALANCE;
private String PDRBDED_BOND_BALANCE;
private String PDRBDED_BEGIN_DATE;
private String PDRBDED_END_DATE;
private String PDRBDED_ACTIVITY_DATE;
private String PDRBDED_ARR_RECOVER_MAX;
private String PDRBDED_ADD_REPL_PICT_CODE;
private String PDRBDED_USER_ID;
private String PDRBDED_DATA_ORIGIN;
private String PDRBDED_SURROGATE_ID;
private String PDRBDED_VERSION;
private String PDRBDED_VPDI_CODE;
//getters and setters
public String getPDRBDED_PIDM() {
return PDRBDED_PIDM;
}
public void setPDRBDED_PIDM(String pDRBDED_PIDM) {
PDRBDED_PIDM = pDRBDED_PIDM;
}
public String getPDRBDED_BDCA_CODE() {
return PDRBDED_BDCA_CODE;
}
public void setPDRBDED_BDCA_CODE(String pDRBDED_BDCA_CODE) {
PDRBDED_BDCA_CODE = pDRBDED_BDCA_CODE;
}
public String getPDRBDED_ADD_REPL_IND() {
return PDRBDED_ADD_REPL_IND;
}
public void setPDRBDED_ADD_REPL_IND(String pDRBDED_ADD_REPL_IND) {
PDRBDED_ADD_REPL_IND = pDRBDED_ADD_REPL_IND;
}
public String getPDRBDED_ADD_REPL_EMPL() {
return PDRBDED_ADD_REPL_EMPL;
}
public void setPDRBDED_ADD_REPL_EMPL(String pDRBDED_ADD_REPL_EMPL) {
PDRBDED_ADD_REPL_EMPL = pDRBDED_ADD_REPL_EMPL;
}
public String getPDRBDED_ADD_REPL_EMPR() {
return PDRBDED_ADD_REPL_EMPR;
}
public void setPDRBDED_ADD_REPL_EMPR(String pDRBDED_ADD_REPL_EMPR) {
PDRBDED_ADD_REPL_EMPR = pDRBDED_ADD_REPL_EMPR;
}
public String getPDRBDED_ADD_REPL_TAX_BASE() {
return PDRBDED_ADD_REPL_TAX_BASE;
}
public void setPDRBDED_ADD_REPL_TAX_BASE(String pDRBDED_ADD_REPL_TAX_BASE) {
PDRBDED_ADD_REPL_TAX_BASE = pDRBDED_ADD_REPL_TAX_BASE;
}
public String getPDRBDED_ARR_STATUS() {
return PDRBDED_ARR_STATUS;
}
public void setPDRBDED_ARR_STATUS(String pDRBDED_ARR_STATUS) {
PDRBDED_ARR_STATUS = pDRBDED_ARR_STATUS;
}
public String getPDRBDED_ARR_BALANCE() {
return PDRBDED_ARR_BALANCE;
}
public void setPDRBDED_ARR_BALANCE(String pDRBDED_ARR_BALANCE) {
PDRBDED_ARR_BALANCE = pDRBDED_ARR_BALANCE;
}
public String getPDRBDED_BOND_BALANCE() {
return PDRBDED_BOND_BALANCE;
}
public void setPDRBDED_BOND_BALANCE(String pDRBDED_BOND_BALANCE) {
PDRBDED_BOND_BALANCE = pDRBDED_BOND_BALANCE;
}
public String getPDRBDED_BEGIN_DATE() {
return PDRBDED_BEGIN_DATE;
}
public void setPDRBDED_BEGIN_DATE(String pDRBDED_BEGIN_DATE) {
PDRBDED_BEGIN_DATE = pDRBDED_BEGIN_DATE;
}
public String getPDRBDED_END_DATE() {
return PDRBDED_END_DATE;
}
public void setPDRBDED_END_DATE(String pDRBDED_END_DATE) {
PDRBDED_END_DATE = pDRBDED_END_DATE;
}
public String getPDRBDED_ACTIVITY_DATE() {
return PDRBDED_ACTIVITY_DATE;
}
public void setPDRBDED_ACTIVITY_DATE(String pDRBDED_ACTIVITY_DATE) {
PDRBDED_ACTIVITY_DATE = pDRBDED_ACTIVITY_DATE;
}
public String getPDRBDED_ARR_RECOVER_MAX() {
return PDRBDED_ARR_RECOVER_MAX;
}
public void setPDRBDED_ARR_RECOVER_MAX(String pDRBDED_ARR_RECOVER_MAX) {
PDRBDED_ARR_RECOVER_MAX = pDRBDED_ARR_RECOVER_MAX;
}
public String getPDRBDED_ADD_REPL_PICT_CODE() {
return PDRBDED_ADD_REPL_PICT_CODE;
}
public void setPDRBDED_ADD_REPL_PICT_CODE(String pDRBDED_ADD_REPL_PICT_CODE) {
PDRBDED_ADD_REPL_PICT_CODE = pDRBDED_ADD_REPL_PICT_CODE;
}
public String getPDRBDED_USER_ID() {
return PDRBDED_USER_ID;
}
public void setPDRBDED_USER_ID(String pDRBDED_USER_ID) {
PDRBDED_USER_ID = pDRBDED_USER_ID;
}
public String getPDRBDED_DATA_ORIGIN() {
return PDRBDED_DATA_ORIGIN;
}
public void setPDRBDED_DATA_ORIGIN(String pDRBDED_DATA_ORIGIN) {
PDRBDED_DATA_ORIGIN = pDRBDED_DATA_ORIGIN;
}
public String getPDRBDED_SURROGATE_ID() {
return PDRBDED_SURROGATE_ID;
}
public void setPDRBDED_SURROGATE_ID(String pDRBDED_SURROGATE_ID) {
PDRBDED_SURROGATE_ID = pDRBDED_SURROGATE_ID;
}
public String getPDRBDED_VERSION() {
return PDRBDED_VERSION;
}
public void setPDRBDED_VERSION(String pDRBDED_VERSION) {
PDRBDED_VERSION = pDRBDED_VERSION;
}
public String getPDRBDED_VPDI_CODE() {
return PDRBDED_VPDI_CODE;
}
public void setPDRBDED_VPDI_CODE(String pDRBDED_VPDI_CODE) {
PDRBDED_VPDI_CODE = pDRBDED_VPDI_CODE;
}
}
package com.learningsolo.spring;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
@Controller
public class FileUploadController {
@Autowired
FileUploadService uploadService;
@RequestMapping(value = "/welcome", method = RequestMethod.GET)
public ModelAndView index() {
return new ModelAndView("upload");
}
@RequestMapping(value = "/upload", method = RequestMethod.POST)
public ModelAndView singleFileUpload(@RequestParam("file") MultipartFile file,
RedirectAttributes redirectAttributes) {
if (file.isEmpty()) {
redirectAttributes.addFlashAttribute("message", "Please select a file to upload");
return new ModelAndView("upload","message", "Please select a file to upload");
}
try {
// Get the file and save it somewhere
byte[] bytes = file.getBytes();
Path path = Paths.get("C://Windows//Temp//" + file.getOriginalFilename());
Files.write(path, bytes);
uploadService.uploadFileData("C://Windows//Temp//"+path.getFileName());
redirectAttributes.addFlashAttribute("message",
"Has subido correctamente '" + file.getOriginalFilename() + "'");
} catch (IOException e) {
redirectAttributes.addFlashAttribute("message",
"Se produjo un error durante la carga '" + file.getOriginalFilename() + "'");
e.printStackTrace();
}
return new ModelAndView("upload","message", "Has subido correctamente '" + file.getOriginalFilename() + "'");
}
}
package com.learningsolo.spring;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class FileUploadDao extends BaseDAO{
public boolean saveFileDataInDB(List<ExcelTemplateVO> employeeList){
String sql = "insert into CABECERA (PDRBDED_PIDM, PDRBDED_BDCA_CODE, PDRBDED_ADD_REPL_IND, PDRBDED_ADD_REPL_EMPL,"
+ " PDRBDED_ADD_REPL_EMPR, PDRBDED_ADD_REPL_TAX_BASE, PDRBDED_ADD_REPL_TAX_BASE, PDRBDED_ARR_BALANCE,"
+ " PDRBDED_BOND_BALANCE, PDRBDED_BEGIN_DATE, PDRBDED_END_DATE, PDRBDED_ACTIVITY_DATE,"
+ " PDRBDED_ARR_RECOVER_MAX, PDRBDED_ADD_REPL_PICT_CODE, PDRBDED_USER_ID, PDRBDED_DATA_ORIGIN,"
+ " PDRBDED_SURROGATE_ID,PDRBDED_VERSION, PDRBDED_VPDI_CODE) "
+ " VALUES (:PDRBDED_PIDM, :PDRBDED_BDCA_CODE, :PDRBDED_ADD_REPL_IND, :PDRBDED_ADD_REPL_EMPL,"
+ " :PDRBDED_ADD_REPL_EMPR, :PDRBDED_ADD_REPL_TAX_BASE, :PDRBDED_ADD_REPL_TAX_BASE, :PDRBDED_ARR_BALANCE,"
+ " :PDRBDED_BOND_BALANCE, :PDRBDED_BEGIN_DATE, :PDRBDED_END_DATE, :PDRBDED_ACTIVITY_DATE,"
+ " :PDRBDED_ARR_RECOVER_MAX, :PDRBDED_ADD_REPL_PICT_CODE, :PDRBDED_USER_ID, :PDRBDED_DATA_ORIGIN,"
+ " :PDRBDED_SURROGATE_ID,:PDRBDED_VERSION, :PDRBDED_VPDI_CODE)";
try {
List<Map<String, String>> batchUpdateParams = new ArrayList<>();
for(ExcelTemplateVO vo : employeeList){
Map<String, String> paramMap = new HashMap<>();
paramMap.put("PDRBDED_PIDM", vo.getPDRBDED_PIDM());
paramMap.put("PDRBDED_BDCA_CODE", vo.getPDRBDED_BDCA_CODE());
paramMap.put("PDRBDED_ADD_REPL_IND", vo.getPDRBDED_ADD_REPL_IND());
paramMap.put("PDRBDED_ADD_REPL_EMPL", vo.getPDRBDED_ADD_REPL_EMPL());
paramMap.put("PDRBDED_ADD_REPL_EMPR", vo.getPDRBDED_ADD_REPL_EMPR());
paramMap.put("PDRBDED_ADD_REPL_TAX_BASE", vo.getPDRBDED_ADD_REPL_TAX_BASE());
paramMap.put("PDRBDED_ARR_STATUS", vo.getPDRBDED_ARR_STATUS());
paramMap.put("PDRBDED_ARR_BALANCE", vo.getPDRBDED_ARR_BALANCE());
paramMap.put("PDRBDED_BOND_BALANCE", vo.getPDRBDED_BOND_BALANCE());
paramMap.put("PDRBDED_BEGIN_DATE", vo.getPDRBDED_BEGIN_DATE());
paramMap.put("PDRBDED_END_DATE", vo.getPDRBDED_END_DATE());
paramMap.put("PDRBDED_ACTIVITY_DATE", vo.getPDRBDED_ACTIVITY_DATE());
paramMap.put("PDRBDED_ARR_RECOVER_MAX", vo.getPDRBDED_ARR_RECOVER_MAX());
paramMap.put("PDRBDED_ADD_REPL_PICT_CODE", vo.getPDRBDED_ADD_REPL_PICT_CODE());
paramMap.put("PDRBDED_USER_ID", vo.getPDRBDED_USER_ID());
paramMap.put("PDRBDED_DATA_ORIGIN", vo.getPDRBDED_DATA_ORIGIN());
paramMap.put("PDRBDED_SURROGATE_ID", vo.getPDRBDED_SURROGATE_ID());
paramMap.put("PDRBDED_VERSION", vo.getPDRBDED_VERSION());
paramMap.put("PDRBDED_VPDI_CODE", vo.getPDRBDED_VPDI_CODE());
batchUpdateParams.add(paramMap);
}
getNamedParamJdbcTemplate().batchUpdate(sql, batchUpdateParams.toArray(new Map[batchUpdateParams.size()] ));
} catch (Exception e) {
e.printStackTrace();
return false;
}
return true;
}
}
package com.learningsolo.spring;
import java.io.File;
import java.io.FileInputStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Iterator;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
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 org.springframework.beans.factory.annotation.Autowired;
public class FileUploadService {
@Autowired
FileUploadDao fileUploadDao;
public String uploadFileData(String inputFilePath){
Workbook workbook = null;
Sheet sheet = null;
try
{
workbook = getWorkBook(new File(inputFilePath));
sheet = workbook.getSheetAt(0);
/*Build the header portion of the Output File*/
String headerDetails= "PDRBDED_PIDM, PDRBDED_BDCA_CODE, PDRBDED_ADD_REPL_IND, PDRBDED_ADD_REPL_EMPL,"
+ "PDRBDED_ADD_REPL_EMPR, PDRBDED_ADD_REPL_TAX_BASE, PDRBDED_ADD_REPL_TAX_BASE, PDRBDED_ARR_BALANCE,"
+ "PDRBDED_BOND_BALANCE, PDRBDED_BEGIN_DATE, PDRBDED_END_DATE, PDRBDED_ACTIVITY_DATE,"
+ "PDRBDED_ARR_RECOVER_MAX, PDRBDED_ADD_REPL_PICT_CODE, PDRBDED_USER_ID, PDRBDED_DATA_ORIGIN,"
+ "PDRBDED_SURROGATE_ID,PDRBDED_VERSION, PDRBDED_VPDI_CODE";
String headerNames[] = headerDetails.split(",");
/*Read and process each Row*/
ArrayList<ExcelTemplateVO> employeeList = new ArrayList<>();
Iterator<Row> rowIterator = sheet.iterator();
while(rowIterator.hasNext())
{
Row row = rowIterator.next();
//Read and process each column in row
ExcelTemplateVO excelTemplateVO = new ExcelTemplateVO();
int count=0;
while(count<headerNames.length){
String methodName = "set"+headerNames[count];
String inputCellValue = getCellValueBasedOnCellType(row,count++);
setValueIntoObject(excelTemplateVO, ExcelTemplateVO.class, methodName, "java.lang.String", inputCellValue);
}
employeeList.add(excelTemplateVO);
}
fileUploadDao.saveFileDataInDB(employeeList);
}
catch(Exception ex){
ex.printStackTrace();
}
return "Success";
}
public static Workbook getWorkBook(File fileName)
{
Workbook workbook = null;
try {
String myFileName=fileName.getName();
String extension = myFileName.substring(myFileName.lastIndexOf("."));
if(extension.equalsIgnoreCase(".xls")){
workbook = new HSSFWorkbook(new FileInputStream(fileName));
}
else if(extension.equalsIgnoreCase(".xlsx")){
workbook = new XSSFWorkbook(new FileInputStream(fileName));
}
}
catch(Exception ex)
{
ex.printStackTrace();
}
return workbook;
}
public static String getCellValueBasedOnCellType(Row rowData,int columnPosition)
{
String cellValue=null;
Cell cell = rowData.getCell(columnPosition);
if(cell!=null){
if(cell.getCellType()==Cell.CELL_TYPE_STRING)
{
String inputCellValue=cell.getStringCellValue();
if(inputCellValue.endsWith(".0")){
inputCellValue=inputCellValue.substring(0, inputCellValue.length()-2);
}
cellValue=inputCellValue;
}
else if (cell.getCellType()==Cell.CELL_TYPE_NUMERIC)
{
Double doubleVal = new Double(cell.getNumericCellValue());
cellValue= Integer.toString(doubleVal.intValue());
}
}
return cellValue;
}
private static <T> void setValueIntoObject(Object obj, Class<T> clazz, String methodNameForField, String dataType, String inputCellValue)
throws SecurityException, NoSuchMethodException, ClassNotFoundException, NumberFormatException, IllegalArgumentException, IllegalAccessException, InvocationTargetException{
Method meth = clazz.getMethod(methodNameForField, Class.forName(dataType));
T t = clazz.cast(obj);
if("java.lang.Double".equalsIgnoreCase(dataType))
{
meth.invoke(t, Double.parseDouble(inputCellValue));
}else if(!"java.lang.Integer".equalsIgnoreCase(dataType))
{
meth.invoke(t, inputCellValue);
}
else
{
meth.invoke(t, Integer.parseInt(inputCellValue));
}
}
}
Manifest-Version: 1.0
Built-By: FAMILIA HOLGUIN
Build-Jdk: 1.8.0_221
Created-By: Maven Integration for Eclipse
#Generated by Maven Integration for Eclipse
#Wed Sep 25 09:29:35 COT 2019
version=0.0.1-SNAPSHOT
groupId=com.learningsolo.spring
m2e.projectName=springFileUpload
m2e.projectLocation=C\:\\Users\\cesar\\Desktop\\Nueva carpeta\\Spring-Examples-master\\SpringFileUploadToDB
artifactId=springFileUpload
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.learningsolo.spring</groupId>
<artifactId>springFileUpload</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>FileUpload</name>
<description>FileUpload</description>
<properties>
<jdk.version>1.8</jdk.version>
<spring.version>4.3.7.RELEASE</spring.version>
<jstl.version>1.2</jstl.version>
<servletapi.version>3.1.0</servletapi.version>
<logback.version>1.1.3</logback.version>
<jcl.slf4j.version>1.7.12</jcl.slf4j.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>${jstl.version}</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.9</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.9</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml-schemas</artifactId>
<version>3.9</version>
</dependency>
<!-- compile only, deployed container will provide this -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>${servletapi.version}</version>
<scope>provided</scope>
</dependency>
<!-- Logging -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>${jcl.slf4j.version}</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
</configuration>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment