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.ResultSet;
|
7 |
import java.sql.SQLException;
|
8 |
import java.sql.Statement;
|
9 |
|
10 |
import javax.servlet.ServletException;
|
11 |
import javax.servlet.annotation.WebServlet;
|
12 |
import javax.servlet.http.HttpServlet;
|
13 |
import javax.servlet.http.HttpServletRequest;
|
14 |
import javax.servlet.http.HttpServletResponse;
|
15 |
|
16 |
|
17 |
@WebServlet("/DbConnectionProbe")
|
18 |
public class DbConnectionProbe extends HttpServlet {
|
19 |
private static final long serialVersionUID = 1L;
|
20 |
|
21 |
public DbConnectionProbe() {
|
22 |
super();
|
23 |
// TODO Auto-generated constructor stub
|
24 |
}
|
25 |
|
26 |
|
27 |
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
28 |
response.setContentType("text/html");
|
29 |
PrintWriter out = response.getWriter();
|
30 |
|
31 |
//out.print("<html><head><title>DaoAdresseService</title></head><body>");
|
32 |
//out.print("<h2>DaoAdresseService</h2>");
|
33 |
|
34 |
try (
|
35 |
Connection conn = DBConnection.getConnection();
|
36 |
Statement stmt = conn.createStatement()
|
37 |
) {
|
38 |
|
39 |
out.print("Got DB Connection<br>");
|
40 |
|
41 |
try (ResultSet res = stmt.executeQuery("SELECT 1") ) {
|
42 |
out.print("'SELECT 1' query ok");
|
43 |
}
|
44 |
|
45 |
|
46 |
} catch (SQLException e) {
|
47 |
out.print("DB Connection failed: " + e.getMessage());
|
48 |
}
|
49 |
|
50 |
|
51 |
}
|
52 |
|
53 |
}
|