Here you can find the source of getRowCount(Statement stmt, String tableName)
Parameter | Description |
---|---|
stmt | Statement for sql |
tableName | table to check |
Parameter | Description |
---|---|
SQLException | SQLException |
public static int getRowCount(Statement stmt, String tableName) throws SQLException
//package com.java2s; /*//from w w w . j a v a 2 s . c om * Copyright (C) 2008 Michael Romankiewicz * microm at users.sourceforge.net * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; public class Main { /** * Returns the row count of the given table * * @param stmt * Statement for sql * @param tableName * table to check * @return row count * @throws SQLException * SQLException */ public static int getRowCount(Statement stmt, String tableName) throws SQLException { int rowCount = 0; ResultSet rs = stmt.executeQuery("SELECT COUNT(*) FROM " + tableName); if (rs.next()) { rowCount = rs.getInt(1); } rs.close(); return rowCount; } }