1 |
torben |
2267 |
package dk.daoas.daoadresseservice.db;
|
2 |
|
|
|
3 |
|
|
import java.sql.Connection;
|
4 |
|
|
import java.sql.SQLException;
|
5 |
|
|
|
6 |
|
|
import javax.naming.Context;
|
7 |
|
|
import javax.naming.InitialContext;
|
8 |
|
|
import javax.naming.NamingException;
|
9 |
|
|
import javax.sql.DataSource;
|
10 |
|
|
|
11 |
|
|
/*
|
12 |
|
|
Husk at tilføje denne til {TOMCAT}/conf/context.xml og tilrette password.
|
13 |
|
|
|
14 |
|
|
<Resource auth="Container"
|
15 |
|
|
driverClassName="com.mysql.jdbc.Driver"
|
16 |
|
|
maxActive="10"
|
17 |
|
|
maxIdle="5"
|
18 |
|
|
maxWait="10000"
|
19 |
|
|
name="jdbc/fulddaekning"
|
20 |
|
|
password=""
|
21 |
|
|
type="javax.sql.DataSource"
|
22 |
|
|
url="jdbc:mysql://10.30.2.51:3306/fulddaekning" username="import"/>
|
23 |
|
|
|
24 |
|
|
*/
|
25 |
|
|
|
26 |
|
|
public class DBConnection {
|
27 |
|
|
public static Connection getConnection() throws SQLException{
|
28 |
|
|
try {
|
29 |
|
|
|
30 |
|
|
Context initContext = new InitialContext();
|
31 |
|
|
Context envContext = (Context)initContext.lookup("java:/comp/env");
|
32 |
|
|
|
33 |
|
|
DataSource ds = (DataSource) envContext.lookup("jdbc/fulddaekning");
|
34 |
|
|
return ds.getConnection();
|
35 |
|
|
} catch (NamingException e) {
|
36 |
|
|
throw new SQLException("invalid data source: " +e.getMessage(), e);
|
37 |
|
|
}
|
38 |
|
|
}
|
39 |
|
|
}
|