public static void start() throws Exception { try { SocketConnector connector = new SocketConnector(); connector.setPort(8080); server.setConnectors(new Connector[] {connector}); WebAppContext context = new WebAppContext(); context.setServer(server); context.setContextPath("/DBService"); // context.setContextPath("/"); context.setWar("src/main/webapp"); server.addHandler(context); SQLExecutor.setConfigfile("local_logging.properties"); server.start(); } catch (Exception e) { if (server != null) { try { server.stop(); } catch (Exception e1) { throw new RuntimeException(e1); } } } }
public class DBUtil { // protected final Connection conn; // protected Statement stmt; protected SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ssZ"); protected SQLExecutor stmt = SQLExecutor.getInstance(); public DBUtil() {} protected String toDateString(Date date) { return "TIMESTAMP '" + format.format(date) + "'"; // return "TIMESTAMP WITH TIME ZONE 'epoch' +" + date.getTime() + "* INTERVAL '1 second'"; } protected List<? extends DBObject> generateObjectList(DBObject element, ResultSet res) { try { List<DBObject> result = new LinkedList<DBObject>(); while (res.next()) { DBObject dbob = (element.getClass().newInstance()).getDBObject(res); result.add(dbob); } return result; } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InstantiationException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; } }