Source code: nserverdemo/NetworkServerUtil.java
1 /*
2
3 Derby - Class nserverdemo.NetworkServerUtil
4
5 Copyright 2003, 2004 The Apache Software Foundation or its licensors, as applicable.
6
7 Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at
10
11 http://www.apache.org/licenses/LICENSE-2.0
12
13 Unless required by applicable law or agreed to in writing, software
14 distributed under the License is distributed on an "AS IS" BASIS,
15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 See the License for the specific language governing permissions and
17 limitations under the License.
18
19 */
20
21 package nserverdemo;
22
23 import java.util.Properties;
24 import java.sql.SQLException;
25 import java.sql.DriverManager;
26 import java.io.IOException;
27 import java.sql.Statement;
28 import java.sql.ResultSet;
29 import java.sql.SQLException;
30 import java.sql.SQLWarning;
31 import java.io.PrintWriter;
32 import java.net.InetAddress;
33
34 import org.apache.derby.drda.NetworkServerControl; //derby network server
35 import java.io.FileOutputStream;
36
37 /**
38 * Class for starting the Derby NetworkServer on a separate Thread.
39 * This class provides methods to start, and shutdown the server
40 */
41
42 public class NetworkServerUtil {
43
44 private int portNum;
45 private NetworkServerControl serverControl;
46 private PrintWriter pw;
47
48 public NetworkServerUtil(int port, PrintWriter pw) {
49
50 this.portNum = port;
51 this.pw = pw;
52 try {
53 serverControl = new
54 NetworkServerControl(InetAddress.getByName("localhost"), port);
55 pw.println("Derby Network Server created");
56 } catch (Exception e) {
57 e.printStackTrace();
58 }
59 }
60
61 /**
62 * trace utility of server
63 */
64 public void trace(boolean onoff) {
65 try {
66 serverControl.trace(onoff);
67 } catch (Exception e) {
68 e.printStackTrace();
69 }
70 }
71
72
73 /**
74 * Try to test for a connection
75 * Throws exception if unable to get a connection
76 */
77 public void testForConnection()
78 throws Exception {
79 serverControl.ping();
80 }
81
82
83 /**
84 * Shutdown the NetworkServer
85 */
86 public void shutdown() {
87 try {
88 serverControl.shutdown();
89 } catch (Exception e) {
90 e.printStackTrace();
91 }
92 }
93
94
95 /**
96 * Start Derby Network server
97 *
98 */
99 public void start() {
100 try {
101 serverControl.start(pw);
102 } catch (Exception e) {
103 e.printStackTrace();
104 }
105 }
106
107
108 }
109
110
111