@Override public boolean connect() { try { Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance(); String url = "jdbc:sqlserver://" + Config.DATABASE_IP + ":" + Config.DATABASE_PORT + ";databaseName=Narda"; conn = DriverManager.getConnection(url, Config.DATABASE_USERNAME, Config.DATABASE_PASSWORD); OrbitStamps.log(OrbitStamps.LOG_NOTICE, "HuddingeDataMapper: connection success!"); return true; } catch (ClassNotFoundException ex) { System.err.println(ex.getMessage()); } catch (IllegalAccessException ex) { System.err.println(ex.getMessage()); } catch (InstantiationException ex) { System.err.println(ex.getMessage()); } catch (SQLException ex) { System.err.println(ex.getMessage()); } OrbitStamps.log(OrbitStamps.LOG_NOTICE, "HuddingeDataMapper: connection failed!"); return false; }
private void getAndPopulateEvents(String roomID) { // Get and populate event info Room r = OrbitStamps.operatingRooms.get(roomID); DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); for (Entry<String, Operation> opEntry : r.operations.entrySet()) { Operation op = opEntry.getValue(); Statement stmnt; Timestamp lastEvent = op.stamps.peekFirst(); try { stmnt = conn.createStatement(); String strQuery; if (lastEvent == null) { strQuery = "select handelse, tidpunkt from " + Config.DATABASE_EVENT_VIEW + " WHERE optillfalle_id = " + op.op_id; } else { strQuery = "select handelse, tidpunkt from " + Config.DATABASE_EVENT_VIEW + " WHERE optillfalle_id = " + op.op_id; } ResultSet res = stmnt.executeQuery(strQuery); OrbitStamps.log( OrbitStamps.LOG_NOTICE, "GetAndPopulateEvents: op stamps opid= " + op.op_id); while (res.next()) { try { String handelse = res.getString("handelse"); String tidpunkt = res.getString("tidpunkt"); Timestamp newStamp = new Timestamp(Integer.toString(OrbitStamps.stampStringToOrder.get(handelse))); OrbitStamps.log(OrbitStamps.LOG_NOTICE, tidpunkt); newStamp.time = Calendar.getInstance().getTime(); // df.parse(tidpunkt); newStamp.stringStamp = handelse; OrbitStamps.log( OrbitStamps.LOG_NOTICE, "GetAndPopulateEvents: Found timestamp= " + handelse); if (!op.stamps.contains(newStamp)) { op.stamps.addFirst(newStamp); } } catch (/*ParseException e*/ Exception e) { e.printStackTrace(); } } } catch (SQLException e) { e.printStackTrace(); } } }