Java SQL Table count(Connection conn, String table)

Here you can find the source of count(Connection conn, String table)

Description

count

License

Open Source License

Declaration

public static long count(Connection conn, String table) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

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

public class Main {
    public static long count(Connection conn, String table) {
        long ret = 0;
        try {//from w ww  .  j  a  v  a  2s . c  om
            Statement statement = conn.createStatement();
            String sql = String.format("select count(*) from %s;", table);
            ResultSet set = statement.executeQuery(sql);

            if (set.next()) {

                ret = set.getLong(1);

            }

            statement.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }

        return ret;
    }
}

Related

  1. clearTables(Connection conn)
  2. clearTables(Connection conn, String[] tables)
  3. clearTables(Connection connection)
  4. columnExist(String table, String column, Connection con)
  5. constructObject(Class theClass, Connection db, int objectId, String tableName, String uniqueField)
  6. countTables(Connection connection)
  7. createBagValuesTables(Connection con)
  8. createFreqTable()
  9. createHSQLTables(LineNumberReader reader, Statement statement)