我的MYSQL表格有3个表。
我无法使给出的示例工作。
在Java中,使用java.sql.*
,我想知道整个数据库还剩下多少空间,因为空间非常有限。
以下是我的方法:
// this.conn = DriverManager.getConnection("jdbc:mysql://......");
public long remainingSpace() {
String sql = "SELECT table_schema AS \"Database\", "
+ "ROUND(SUM(data_length + index_length) / 1024, 2) AS \"Size (KB)\" "
+ "FROM information_schema.TABLES GROUP BY table_schema;";
ResultSet rs;
PreparedStatement prpSttm = this.conn.prepareStatement(sql);
rs = prpSttm.executeQuery();
rs.next();
long remainingSpace = rs.getInt("Size (KB)");
return remainingSpace;
}
这个返回 9
(KB)。
phpMyAdmin告诉我我一个表里有64 KiB
的数据:
我该如何在Java中获取正确的大小?
information_schema | 9.00 sql560710 | 96.00
谢谢! - phil294