Here you can find the source of countTable(DataSource dataSource, String tableName)
public static int countTable(DataSource dataSource, String tableName) throws Exception
//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(); } }