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

Contents of /dao/DaoAdresseService/src/main/java/dk/daoas/daoadresseservice/db/DbConnectionProbe.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2356 - (show annotations) (download)
Tue Feb 24 07:57:47 2015 UTC (9 years, 3 months ago) by torben
Original Path: dao/DaoAdresseService/src/dk/daoas/daoadresseservice/db/DbConnectionProbe.java
File size: 1318 byte(s)
Add link to connection probe
1 package dk.daoas.daoadresseservice.db;
2
3 import java.io.IOException;
4 import java.io.PrintWriter;
5 import java.sql.Connection;
6 import java.sql.SQLException;
7 import java.sql.Statement;
8
9 import javax.servlet.ServletException;
10 import javax.servlet.annotation.WebServlet;
11 import javax.servlet.http.HttpServlet;
12 import javax.servlet.http.HttpServletRequest;
13 import javax.servlet.http.HttpServletResponse;
14
15
16 @WebServlet("/DbConnectionProbe")
17 public class DbConnectionProbe extends HttpServlet {
18 private static final long serialVersionUID = 1L;
19
20 public DbConnectionProbe() {
21 super();
22 // TODO Auto-generated constructor stub
23 }
24
25 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
26 response.setContentType("text/html");
27 PrintWriter out = response.getWriter();
28
29 out.print("<html><head><title>DaoAdresseService</title></head><body>");
30 out.print("<h2>DaoAdresseService</h2>");
31
32 try (
33 Connection conn = DBConnection.getConnection();
34 Statement stmt = conn.createStatement()
35 ) {
36
37 stmt.executeQuery("SELECT 1");
38
39 out.print("Got DB Connection");
40
41 } catch (SQLException e) {
42 out.print("DB Connection failed: " + e.getMessage());
43 }
44
45
46 }
47
48 }

  ViewVC Help
Powered by ViewVC 1.1.20