@RequestMapping( value = "/clear", params = {"tableName"}, method = RequestMethod.POST) public String clearing( Model model, @RequestParam(value = "tableName") String tableName, HttpSession session) { DatabaseManager manager = getManager(session); try { manager.clear(tableName); } catch (SQLException e) { e.printStackTrace(); return "error"; } return "success"; }
@RequestMapping( value = "/find", params = {"tableName"}, method = RequestMethod.POST) public String finding( Model model, @RequestParam(value = "tableName") String tableName, HttpSession session) { DatabaseManager manager = getManager(session); List<String> tableData = null; try { tableData = manager.find(tableName); } catch (SQLException e) { e.printStackTrace(); return "error"; } model.addAttribute("table", getLists(tableData)); return "find"; }
@RequestMapping(value = "/deleteRecord", method = RequestMethod.POST) public String deleting( Model model, @RequestParam(value = "tableName") String tableName, @RequestParam(value = "keyName") String keyName, @RequestParam(value = "keyValue") String keyValue, HttpSession session) { DatabaseManager manager = getManager(session); if (manager == null) { return "redirect:connect"; } try { manager.deleteRecord(tableName, keyName, keyValue); } catch (Exception e) { e.printStackTrace(); return "error"; } return "success"; }
@RequestMapping( value = "/create", params = {"tableName"}, method = RequestMethod.POST) public String creating( HttpSession session, @RequestParam(value = "tableName") String tableName, HttpServletRequest req) { try { DatabaseManager manager = getManager(session); Map<String, Object> inputData = new HashMap<>(); for (int index = 1; index <= getColumnCount(manager, tableName); index++) { inputData.put( req.getParameter("columnName" + index), req.getParameter("columnValue" + index)); manager.create(tableName, inputData); } } catch (Exception e) { e.printStackTrace(); return "error"; } return "success"; }
private int getColumnCount(DatabaseManager manager, String tableName) throws Exception { return Integer.parseInt(manager.find(tableName).get(0)); }