使用Java计算MySQL表大小

使用Java计算MySQL表大小,java,mysql,database,rest,crud,Java,Mysql,Database,Rest,Crud,我需要使用JAVA计算MySQL表的大小,我使用下面的查询。同样,我无法使用java代码获取 查询: SELECT ROUND((DATA_LENGTH + INDEX_LENGTH) / 1024 ) AS Size FROM information_schema.TABLES WHERE TABLE_SCHEMA = "testdb" Application.properties: spring.datasource.url=jdbc:mysql://localho

我需要使用JAVA计算MySQL表的大小,我使用下面的查询。同样,我无法使用java代码获取

查询:

SELECT ROUND((DATA_LENGTH + INDEX_LENGTH) / 1024 ) AS Size 
FROM information_schema.TABLES 
WHERE TABLE_SCHEMA = "testdb"
Application.properties:

spring.datasource.url=jdbc:mysql://localhost:3306/testdb?useSSL=false&serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=XXXXXX
控制器:

@GetMapping("/getSize")
public @ResponseBody long getSize() {
    return schema.sizeOfTable("testdb");
}
回购:


实体类需要进行一些更改,请建议。提前感谢

我需要使用JAVA计算MySQL表的大小,我使用下面的查询。为了什么目的?也许从文件系统中检索此数据更安全?我必须使用rest端点仅获取表的大小。我的意思是表数据+索引大小和表文件大小将不同。。。这个差异可能已经足够大了,那么我可以使用任何查询来获取MySQL中表的大小,并使用rest检索相同的数据。
public interface Schema extends CrudRepository<Tables, String> {
      @Query("SELECT ROUND((DATA_LENGTH + INDEX_LENGTH) / 1024 ) AS Size FROM information_schema.TABLES WHERE TABLE_SCHEMA = :schema")
      public long sizeOfTable(@Param("schema") String schema);
}
 @Entity
 @Table(name = "TABLES", schema = "information_schema")
 public class Tables {
     private Long size;
     public Tables() {
     }
     public Tables(Long size) {
       this.size = size;
     }
 }