Here you can find the source of getTableSize(Connection conn, String tableName)
Gets the record size from the database with the given table.
Parameter | Description |
---|---|
conn | the Connection to execute. |
tableName | the table name (tracking_info). |
Parameter | Description |
---|---|
Exception | if any error occurs. |
public static int getTableSize(Connection conn, String tableName) throws Exception
//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(); } } } }