elunez/eladmin · error · BadRequestException
Database not exist
Error message
Database not exist
What it means
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.
Source
Thrown at eladmin-system/src/main/java/me/zhengjie/modules/maint/rest/DatabaseController.java:121
}
@Log("执行SQL脚本")
@ApiOperation(value = "执行SQL脚本")
@PostMapping(value = "/upload")
@PreAuthorize("@el.check('database:add')")
public ResponseEntity<Object> uploadDatabase(@RequestBody MultipartFile file, HttpServletRequest request)throws Exception{
String id = request.getParameter("id");
DatabaseDto database = databaseService.findById(id);
String fileName;
if(database != null){
fileName = FileUtil.verifyFilename(file.getOriginalFilename());
File executeFile = new File(fileSavePath + fileName);
FileUtil.del(executeFile);
file.transferTo(executeFile);
String result = SqlUtils.executeFile(database.getJdbcUrl(), database.getUserName(), database.getPwd(), executeFile);
return new ResponseEntity<>(result,HttpStatus.OK);
}else{
throw new BadRequestException("Database not exist");
}
}
}
View on GitHub (pinned to 55fbf70595)
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.
Example fix
// before POST /api/database/uploadDatabase?id=99 (no such row) -> 400 Database not exist // after GET /api/database -> find row, e.g. id=3 POST /api/database/uploadDatabase?id=3 with multipart 'file'
Defensive patterns
Strategy: validation
Validate before calling
// Verify the id resolves to a Database before uploading
DatabaseDto db = databaseService.findById(id);
if (db == null) {
return badRequest("Database not exist: refresh and pick a valid database");
}
uploadFile("/api/database/uploadDatabase?id=" + id, sqlFile); Type guard
boolean isExistingDatabaseId(String id) {
return id != null && id.matches("\\d+") && databaseService.findById(id) != null;
} Try / catch
try {
return postMultipart("/api/database/uploadDatabase?id=" + id, file);
} catch (BadRequestException e) {
if ("Database not exist".equals(e.getMessage())) { reloadDatabases(); return retryOnce(); }
throw e;
} Prevention
- 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.
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- 部署信息不存在
- 包对应应用信息不存在
- 文件超出规定大小:{maxSize}MB
- {entity} 不存在: {parameter} is {value}
- Unable to get driver instance: {jdbcUrl}
AI-assisted analysis of elunez/eladmin@55fbf70595 (2026-08-14).
Data as JSON: /api/errors/ce2e4b5c792c9e36.
Report an issue: GitHub.