Here you can find the source of selectCount(DataSource ds, String tableName)
public static int selectCount(DataSource ds, String tableName)
//package com.java2s; import javax.sql.DataSource; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; public class Main { public static int selectCount(DataSource ds, String tableName) { try (Connection conn = ds.getConnection()) { ResultSet resultset = conn.createStatement() .executeQuery(String.format("SELECT count(1) FROM %s", tableName)); if (resultset.next()) { return resultset.getInt(1); } else { return Integer.MIN_VALUE; }// w w w .jav a2 s .c o m } catch (SQLException sqle) { throw new RuntimeException("select failed", sqle); } } }