-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDBSampleServiceLifeCycle.java
More file actions
40 lines (34 loc) · 1.37 KB
/
DBSampleServiceLifeCycle.java
File metadata and controls
40 lines (34 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package dbsample;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.description.AxisService;
import org.apache.axis2.engine.ServiceLifeCycle;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class DBSampleServiceLifeCycle implements ServiceLifeCycle {
public static final String DB_CONNECTION = "dbconnection";
public void startUp(ConfigurationContext configctx, AxisService service) {
try {
Class.forName("com.mysql.jdbc.Driver");
// Creating the DB connection for the sample DB
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/dbsample",
"root",
"");
//Storing the DB in the ConfigurationContext
configctx.setProperty(DB_CONNECTION, conn);
} catch (Exception e) {
e.printStackTrace();
}
}
public void shutDown(ConfigurationContext configctx, AxisService service) {
Connection conn = (Connection) configctx.getProperty(DB_CONNECTION);
if (conn != null) {
try {
// closing the DB
conn.close();
} catch (SQLException e) {
System.out.println("Error while closing the DB connection");
}
}
}
}