/[projects]/dao/DaoAdresseService/src/dk/daoas/daoadresseservice/db/DBConnection.java
ViewVC logotype

Annotation of /dao/DaoAdresseService/src/dk/daoas/daoadresseservice/db/DBConnection.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2355 - (hide annotations) (download)
Tue Feb 24 07:43:04 2015 UTC (9 years, 3 months ago) by torben
File size: 1185 byte(s)
Add comment regarding connection validation
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 torben 2355 url="jdbc:mysql://10.30.2.51:3306/fulddaekning" username="import"
23 torben 2267
24 torben 2355 testOnBorrow="true"
25     validationQuery="SELECT 1"
26    
27     />
28    
29 torben 2267 */
30    
31     public class DBConnection {
32     public static Connection getConnection() throws SQLException{
33     try {
34    
35     Context initContext = new InitialContext();
36     Context envContext = (Context)initContext.lookup("java:/comp/env");
37    
38     DataSource ds = (DataSource) envContext.lookup("jdbc/fulddaekning");
39     return ds.getConnection();
40     } catch (NamingException e) {
41     throw new SQLException("invalid data source: " +e.getMessage(), e);
42     }
43     }
44     }

  ViewVC Help
Powered by ViewVC 1.1.20