Here you can find the source of getProductAllCount(DataSource ds, String key, String sql_allcount)
public static int getProductAllCount(DataSource ds, String key, String sql_allcount) throws Exception
//package com.java2s; //License from project: Apache License import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import javax.sql.DataSource; public class Main { public static int getProductAllCount(DataSource ds, String key, String sql_allcount) throws Exception { Connection c = null;/*from w ww .j a v a 2s.c o m*/ PreparedStatement ps = null; ResultSet rs = null; int ret = 0; try { c = ds.getConnection(); ps = c.prepareStatement(sql_allcount, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); ps.setString(1, key); rs = ps.executeQuery(); if (rs.first()) { ret = rs.getInt(1); } } catch (SQLException se) { throw new Exception("SQLException: " + se.getMessage()); } finally { if (rs != null) rs.close(); if (ps != null) ps.close(); if (c != null) c.close(); } return ret; } }