1 |
package com.grundfos.gmatou.dataupload;
|
2 |
|
3 |
|
4 |
import java.sql.Connection;
|
5 |
import java.sql.SQLException;
|
6 |
|
7 |
import javax.naming.InitialContext;
|
8 |
import javax.naming.NamingException;
|
9 |
import javax.sql.DataSource;
|
10 |
|
11 |
public class DBConnection {
|
12 |
|
13 |
|
14 |
public static Connection getDbConnection() throws NamingException,SQLException {
|
15 |
//when using tomcat we need to prefix with java:comp/env/
|
16 |
DataSource source = (DataSource) new InitialContext().lookup("java:comp/env/jdbc/dataupload");
|
17 |
Connection conn = source.getConnection();
|
18 |
|
19 |
return conn;
|
20 |
}
|
21 |
|
22 |
}
|