-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implementing an interface for making db connections
- Loading branch information
1 parent
f14c1c0
commit 5fee93b
Showing
5 changed files
with
116 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
package excel2db.service; | ||
|
||
public interface DBConnection { | ||
|
||
public void establishDBConnection(); | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/excel2db/service/impl/DBConnectionOracleImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package excel2db.service.impl; | ||
|
||
import excel2db.service.DBConnection; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Value; | ||
|
||
public class DBConnectionOracleImpl implements DBConnection { | ||
|
||
// connection parameters | ||
@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; | ||
|
||
public static final Logger logger = LoggerFactory.getLogger(DBConnectionPostgresImpl.class); | ||
|
||
public void establishDBConnection() { | ||
{ | ||
logger.info("Oracle connection is not implemented yet"); | ||
} | ||
} | ||
|
||
} |
50 changes: 50 additions & 0 deletions
50
src/main/java/excel2db/service/impl/DBConnectionPostgresImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package excel2db.service.impl; | ||
|
||
import excel2db.excel2db; | ||
import excel2db.service.DBConnection; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Value; | ||
|
||
import java.sql.DriverManager; | ||
import java.sql.SQLException; | ||
|
||
public class DBConnectionPostgresImpl implements DBConnection { | ||
|
||
// connection parameters | ||
@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; | ||
|
||
public static final Logger logger = LoggerFactory.getLogger(DBConnectionPostgresImpl.class); | ||
|
||
public void establishDBConnection() { | ||
try { | ||
excel2db.connection = DriverManager.getConnection( | ||
"jdbc:postgresql://" + dbServer + ":" + dbPort + "/" + dbDatabase, dbUser, dbPassword) | ||
; | ||
|
||
} catch (SQLException e) { | ||
logger.error("Connection Failed! Check output console"); | ||
e.printStackTrace(); | ||
return; | ||
} | ||
if (excel2db.connection != null) { | ||
logger.info("Postgres connection is established"); | ||
} else { | ||
logger.error("Failed to make connection!"); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters