Skip to content

Commit

Permalink
handling properties file
Browse files Browse the repository at this point in the history
  • Loading branch information
palych-piter committed Apr 17, 2017
1 parent b47b0ea commit f14c1c0
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 8 deletions.
22 changes: 20 additions & 2 deletions src/main/java/excel2db/excel2db.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;

Expand All @@ -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() {}
Expand Down Expand Up @@ -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)
{
Expand Down
6 changes: 6 additions & 0 deletions src/main/resources/excel2db.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# postgres parameters
db.server=localhost
db.database=excel2db
db.port=5433
db.user=postgres
db.password=postgres
18 changes: 12 additions & 6 deletions src/main/resources/spring.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
<?xml version = "1.0" encoding = "UTF-8"?>

<beans xmlns = "http://www.springframework.org/schema/beans"
xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation = "http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">

<bean id = "excel2db" class = "excel2db.excel2db">
</bean>

<context:component-scan base-package="excel2db" />
<context:property-placeholder location="classpath:excel2db.properties, file:excel2db.properties" ignore-resource-not-found="true"/>

<bean id = "excel2db" class = "excel2db.excel2db"></bean>

</beans>

0 comments on commit f14c1c0

Please sign in to comment.