Пример #1
0
 @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";
 }
Пример #2
0
  @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";
  }
Пример #3
0
  @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";
  }
Пример #4
0
  @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";
  }
Пример #5
0
 private int getColumnCount(DatabaseManager manager, String tableName) throws Exception {
   return Integer.parseInt(manager.find(tableName).get(0));
 }