From f14c1c0a46c49953c11e189979da8de2815ca0ea Mon Sep 17 00:00:00 2001 From: Andrey Bespalov Date: Tue, 18 Apr 2017 00:18:10 +0300 Subject: [PATCH] handling properties file --- src/main/java/excel2db/excel2db.java | 22 ++++++++++++++++++++-- src/main/resources/excel2db.properties | 6 ++++++ src/main/resources/spring.xml | 18 ++++++++++++------ 3 files changed, 38 insertions(+), 8 deletions(-) create mode 100644 src/main/resources/excel2db.properties diff --git a/src/main/java/excel2db/excel2db.java b/src/main/java/excel2db/excel2db.java index 432ca11..96f6127 100644 --- a/src/main/java/excel2db/excel2db.java +++ b/src/main/java/excel2db/excel2db.java @@ -1,7 +1,6 @@ package excel2db; - import com.ge.mdm.tools.common.ApplicationException; import com.ge.mdm.tools.common.SheetEntityManager; import org.apache.commons.io.FilenameUtils; @@ -16,6 +15,7 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; @@ -41,6 +41,22 @@ public class excel2db private String fileExtension; private static Short numberProcessedRecords = Short.valueOf((short)0); + @Value("${db.server}") + String dbServer; + + @Value("${db.user}") + String dbUser; + + @Value("${db.password}") + String dbPassword; + + @Value("${db.port}") + String dbPort; + + @Value("${db.database}") + String dbDatabase; + + Connection connection = null; public excel2db() {} @@ -118,7 +134,9 @@ public void establishPostgresConnection() { try { - connection = DriverManager.getConnection("jdbc:postgresql://localhost:5433/excel2db", "postgres", "postgres"); + connection = DriverManager.getConnection( + "jdbc:postgresql://" + dbServer + ":" + dbPort + "/" + dbDatabase, dbUser, dbPassword) + ; } catch (SQLException e) { diff --git a/src/main/resources/excel2db.properties b/src/main/resources/excel2db.properties new file mode 100644 index 0000000..2c3dcc5 --- /dev/null +++ b/src/main/resources/excel2db.properties @@ -0,0 +1,6 @@ +# postgres parameters +db.server=localhost +db.database=excel2db +db.port=5433 +db.user=postgres +db.password=postgres diff --git a/src/main/resources/spring.xml b/src/main/resources/spring.xml index 8924641..5f481d9 100644 --- a/src/main/resources/spring.xml +++ b/src/main/resources/spring.xml @@ -1,11 +1,17 @@ - + - - + + + + + \ No newline at end of file