{"record":{"id":"ce2e4b5c792c9e36","repo":"elunez/eladmin","slug":"database-not-exist","errorCode":null,"errorMessage":"Database not exist","messagePattern":"Database not exist","errorType":"exception","errorClass":"BadRequestException","httpStatus":400,"severity":"error","filePath":"eladmin-system/src/main/java/me/zhengjie/modules/maint/rest/DatabaseController.java","lineNumber":121,"sourceCode":"\t}\n\n\t@Log(\"执行SQL脚本\")\n\t@ApiOperation(value = \"执行SQL脚本\")\n\t@PostMapping(value = \"/upload\")\n\t@PreAuthorize(\"@el.check('database:add')\")\n\tpublic ResponseEntity<Object> uploadDatabase(@RequestBody MultipartFile file, HttpServletRequest request)throws Exception{\n\t\tString id = request.getParameter(\"id\");\n\t\tDatabaseDto database = databaseService.findById(id);\n\t\tString fileName;\n\t\tif(database != null){\n\t\t\tfileName = FileUtil.verifyFilename(file.getOriginalFilename());\n\t\t\tFile executeFile = new File(fileSavePath + fileName);\n\t\t\tFileUtil.del(executeFile);\n\t\t\tfile.transferTo(executeFile);\n\t\t\tString result = SqlUtils.executeFile(database.getJdbcUrl(), database.getUserName(), database.getPwd(), executeFile);\n\t\t\treturn new ResponseEntity<>(result,HttpStatus.OK);\n\t\t}else{\n\t\t\tthrow new BadRequestException(\"Database not exist\");\n\t\t}\n\t}\n}\n","sourceCodeStart":103,"sourceCodeEnd":125,"githubUrl":"https://github.com/elunez/eladmin/blob/55fbf705956949697dbd68bf9003776609d3d029/eladmin-system/src/main/java/me/zhengjie/modules/maint/rest/DatabaseController.java#L103-L125","documentation":"DatabaseController.uploadDatabase throws BadRequestException('Database not exist') when databaseService.findById(id) returns null for the request parameter 'id'. The upload-and-execute-SQL feature needs an existing Database record (jdbc url, credentials) to run the uploaded file against.","triggerScenarios":"POST /api/database/uploadDatabase?id=<id> with a multipart SQL file where no Database row exists for that id (deleted record, typo'd id, wrong environment).","commonSituations":"Database connection record removed after the page was loaded; passing the database name instead of its numeric id as the id parameter; environment mismatch between frontend and backend data.","solutions":["Reload the database list in the maintenance UI and re-select the target so a fresh, valid id is sent.","Confirm the id parameter is the primary key of database table (numeric), not the db name.","If the record was deleted, recreate it (add the Database entry) before uploading SQL."],"exampleFix":"// before\nPOST /api/database/uploadDatabase?id=99 (no such row) -> 400 Database not exist\n\n// after\nGET /api/database  -> find row, e.g. id=3\nPOST /api/database/uploadDatabase?id=3 with multipart 'file'","handlingStrategy":"validation","validationCode":"// Verify the id resolves to a Database before uploading\nDatabaseDto db = databaseService.findById(id);\nif (db == null) {\n    return badRequest(\"Database not exist: refresh and pick a valid database\");\n}\nuploadFile(\"/api/database/uploadDatabase?id=\" + id, sqlFile);","typeGuard":"boolean isExistingDatabaseId(String id) {\n    return id != null && id.matches(\"\\\\d+\") && databaseService.findById(id) != null;\n}","tryCatchPattern":"try {\n    return postMultipart(\"/api/database/uploadDatabase?id=\" + id, file);\n} catch (BadRequestException e) {\n    if (\"Database not exist\".equals(e.getMessage())) { reloadDatabases(); return retryOnce(); }\n    throw e;\n}","preventionTips":["Reload the database list before executing SQL uploads; ids go stale after deletes.","Send the numeric primary key as 'id', never the database name.","For automation, GET-verify the database record immediately before the upload call."],"tags":["database","not-found","eladmin","file-upload","maintenance"],"backgroundTag":null,"analyzedSha":"55fbf705956949697dbd68bf9003776609d3d029","analyzedAt":"2026-08-14T11:56:12.758Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}