Java DataSource countTable(DataSource dataSource, String tableName)

Here you can find the source of countTable(DataSource dataSource, String tableName)

Description

count Table

License

Open Source License

Declaration

public static int countTable(DataSource dataSource, String tableName) throws Exception 

Method Source Code


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

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

public class Main {
    public static int countTable(DataSource dataSource, String tableName) throws Exception {
        Connection conn = dataSource.getConnection();
        Statement stmt = conn.createStatement();
        ResultSet rs = stmt.executeQuery("select count(*) from " + tableName);
        rs.next();// w  ww . ja  v  a  2 s . c  o m
        conn.close();
        return rs.getInt(1);
    }

    private static void executeQuery(DataSource dataSource, String... queries) throws Exception {
        Connection conn = dataSource.getConnection();
        Statement stmt = conn.createStatement();
        for (String query : queries) {
            stmt.execute(query);
        }
        conn.close();
    }
}

Related

  1. assertNotNull(DataSource dataSource)
  2. batchExecute(DataSource ds, String sql, Object[]... args)
  3. checkTableExists(DataSource dataSource, String tableName)
  4. cleanDB(String ip, DataSource dataSource)
  5. createDataSource()
  6. createDataTable(DataSource dataSource, String tableName)
  7. createDerbyEmbeddedDataSource(Properties props)
  8. createTable(DataSource ds, String ddl)