Created
May 10, 2014 02:41
-
-
Save brnrc/f46bd04e73d604d97127 to your computer and use it in GitHub Desktop.
Relative path to .properties file.
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
package com.timezone.jdbc; | |
import org.apache.commons.dbcp.BasicDataSource; | |
import javax.sql.DataSource; | |
import java.io.FileInputStream; | |
import java.io.IOException; | |
import java.util.Properties; | |
/** | |
* Created by Bruno on 5/6/2014. | |
*/ | |
public class DBCPDataSourceFactory { | |
public static DataSource getDataSource() { | |
Properties props = new Properties(); | |
FileInputStream fis = null; | |
BasicDataSource ds = new BasicDataSource(); | |
try { | |
// getClass().getResource("resources/db.properties").getPath(); | |
fis = new FileInputStream("src/main/resources/db.properties"); | |
props.load(fis); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
return null; | |
} | |
ds.setDriverClassName(props.getProperty("MYSQL_DB_DRIVER_CLASS")); | |
ds.setUrl(props.getProperty("MYSQL_DB_URL")); | |
ds.setUsername(props.getProperty("MYSQL_DB_USERNAME")); | |
ds.setPassword(props.getProperty("MYSQL_DB_PASSWORD")); | |
return ds; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment