Java SQL Table getTableSize(Connection conn, String tableName)

Here you can find the source of getTableSize(Connection conn, String tableName)

Description

Gets the record size from the database with the given table.

License

Open Source License

Parameter

Parameter Description
conn the Connection to execute.
tableName the table name (tracking_info).

Exception

Parameter Description
Exception if any error occurs.

Return

the size of the record in given table.

Declaration

public static int getTableSize(Connection conn, String tableName)
        throws Exception 

Method Source Code

//package com.java2s;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

public class Main {
    /**/*  www. j  a v  a  2  s  . c  o  m*/
     * <p>
     * Gets the record size from the database with the given table.
     * </p>
     * @param conn the Connection to execute.
     * @param tableName the table name (tracking_info).
     * @return the size of the record in given table.
     * @throws Exception if any error occurs.
     */
    public static int getTableSize(Connection conn, String tableName)
            throws Exception {
        Statement statement = null;
        ResultSet rs = null;

        try {
            statement = conn.createStatement();
            rs = statement
                    .executeQuery("SELECT COUNT(*) FROM " + tableName);

            // return the size here.
            rs.next();

            return rs.getInt(1);
        } finally {
            if (rs != null) {
                rs.close();
            }

            if (statement != null) {
                statement.close();
            }
        }
    }
}

Related

  1. getTables(Connection conn)
  2. getTables(Connection connection)
  3. getTables(Connection connection)
  4. getTables(Connection connection)
  5. getTablesFromDatabase(Connection conn)
  6. getTableSize(final Statement statement, final String schema, final String table, boolean scope)
  7. getTotalRows(String tableName, Statement statement)
  8. hasTable(Connection conn, String schemaName, String tableName)
  9. hasTable(String TableName, Connection conn)