-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDbAdapter.java
More file actions
48 lines (39 loc) · 1.28 KB
/
DbAdapter.java
File metadata and controls
48 lines (39 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package com.lftechnology.dao;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.util.Properties;
/**
* DBAdapter for Mysql
* @author achyut
*
*/
public class DbAdapter {
private DbAdapter() {
}
/**
* Get a MYSQL JDBC Connection
* @return Connection
*/
public static Connection setConnection() {
Properties prop = new Properties();
InputStream input = null;
Connection connection = null;
try{
input = new FileInputStream("src/main/java/com/lftechnology/dao/dbconfig.properties");
prop.load(input);
String username = prop.getProperty("dbuser");
String password = prop.getProperty("dbpass");
String url = prop.getProperty("dburl");
connection = DriverManager.getConnection(url, username, password);
input.close();
} catch(FileNotFoundException fnf){
System.out.println("File not found");
} catch (Exception e) {
System.out.println("Couldn't connect to database ="+e.getMessage());
}
return connection;
}
}