1 30 31 32 package org.hsqldb.util; 33 34 import java.sql.Connection ; 35 import java.sql.DriverManager ; 36 import java.sql.SQLException ; 37 import java.sql.Statement ; 38 39 import org.hsqldb.persist.HsqlProperties; 40 41 46 public class ShutdownServer { 47 48 public static void main(String [] arg) { 49 50 boolean webserver; 51 String driver = "org.hsqldb.jdbcDriver"; 52 String url; 53 String user; 54 String password; 55 int port; 56 String defaulturl; 57 String shutdownarg; 58 59 if (arg.length > 0) { 60 String p = arg[0]; 61 62 if ((p != null) && p.startsWith("-?")) { 63 printHelp(); 64 65 return; 66 } 67 } 68 69 HsqlProperties props = HsqlProperties.argArrayToProps(arg, "server"); 70 71 webserver = props.isPropertyTrue("server.webserver", false); 72 defaulturl = webserver ? "jdbc:hsqldb:http://localhost" 73 : "jdbc:hsqldb:hsql://localhost"; 74 75 int defaultport = webserver ? 80 76 : 9001; 77 78 port = props.getIntegerProperty("server.port", defaultport); 79 url = props.getProperty("server.url", defaulturl + ":" + port); 80 user = props.getProperty("server.user", "sa"); 81 password = props.getProperty("server.password", ""); 82 shutdownarg = props.getProperty("server.shutdownarg", ""); 83 84 try { 85 Class.forName(driver); 87 Connection connection = DriverManager.getConnection(url, user, 88 password); 89 Statement statement = connection.createStatement(); 90 91 statement.execute("SHUTDOWN " + shutdownarg); 93 } catch (ClassNotFoundException e) { 94 System.err.println(e); } catch (SQLException e) { 96 System.err.println(e); } 98 } 99 100 static void printHelp() { 101 102 System.out.print( 103 "Usage: java ShutdownServer [-options]\n" 104 + "where options include:\n" 105 + " -port <nr> port where the server is listening\n" 106 + " -user <name> username of admin user\n" 107 + " -password <value> password of admin user\n" 108 + " -webserver <true/false> whether it's a web server\n" 109 + " -url <value> server url (overrides -webserver and -port options)\n" 110 + " -shutdownarg <value> IMMEDIATELY or COMPACT are allowed\n" 111 + "The command line arguments override the default values."); 112 } 113 } 114 | Popular Tags |