1 21 22 package nserverdemo; 23 24 import java.util.Properties ; 25 import java.sql.SQLException ; 26 import java.sql.DriverManager ; 27 import java.io.IOException ; 28 import java.sql.Statement ; 29 import java.sql.ResultSet ; 30 import java.sql.SQLException ; 31 import java.sql.SQLWarning ; 32 import java.io.PrintWriter ; 33 import java.net.InetAddress ; 34 35 import org.apache.derby.drda.NetworkServerControl; import java.io.FileOutputStream ; 37 38 42 43 public class NetworkServerUtil { 44 45 private int portNum; 46 private NetworkServerControl serverControl; 47 private PrintWriter pw; 48 49 public NetworkServerUtil(int port, PrintWriter pw) { 50 51 this.portNum = port; 52 this.pw = pw; 53 try { 54 serverControl = new 55 NetworkServerControl(InetAddress.getByName("localhost"), port); 56 pw.println("Derby Network Server created"); 57 } catch (Exception e) { 58 e.printStackTrace(); 59 } 60 } 61 62 65 public void trace(boolean onoff) { 66 try { 67 serverControl.trace(onoff); 68 } catch (Exception e) { 69 e.printStackTrace(); 70 } 71 } 72 73 74 78 public void testForConnection() 79 throws Exception { 80 serverControl.ping(); 81 } 82 83 84 87 public void shutdown() { 88 try { 89 serverControl.shutdown(); 90 } catch (Exception e) { 91 e.printStackTrace(); 92 } 93 } 94 95 96 100 public void start() { 101 try { 102 serverControl.start(pw); 103 } catch (Exception e) { 104 e.printStackTrace(); 105 } 106 } 107 108 109 } 110 111 112 113 | Popular Tags |