Here you can find the source of getTableSize(final Statement statement, final String schema, final String table, boolean scope)
public static String getTableSize(final Statement statement, final String schema, final String table, boolean scope)
//package com.java2s; //License from project: Apache License import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; public class Main { public static String getTableSize(final Statement statement, final String schema, final String table, boolean scope) { String size = ""; try {/* www .j a v a 2s .co m*/ ResultSet rs = statement.executeQuery(String.format( "SELECT bytes FROM %s" + " WHERE segment_name = UPPER('%s') AND segment_type = 'TABLE'" + " %s AND owner = UPPER('%s')", scope ? "user_segments" : "dba_segments", table, scope ? "--" : "", schema)); while (rs.next()) { Double bytes = rs.getDouble(1); if (bytes > 1024) { size = bytes / (double) 1024 + "KB"; } else if (bytes > 104578) { size = bytes / (double) 1048576 + "MB"; } else if (bytes > 104578 * 1024) { size = bytes / (double) (1048576 * 1024) + "GB"; } } } catch (SQLException ex) { if (ex.getErrorCode() == 942) { throw new RuntimeException(ex.getMessage() + "Internal Error..", ex); } } return size; } }