Spring Rdbms操作(二)——SqlFunction 获取表数据条数
SqlFunction:获取单行结果集。默认返回int。
import javax.sql.DataSource; import org.springframework.jdbc.object.SqlFunction; public class TestSFunction { public TestSFunction() { // TODO Auto-generated constructor stub } public static void main(String[] args) { // TODO Auto-generated method stub TestSFunction tsFunction = new TestSFunction(); int res = tsFunction.countRows(); System.out.println(res); } public int countRows(){ Get_cmd_log cmd_log = new Get_cmd_log(); DataSource datasource = cmd_log.getDataSource(); SqlFunction sqlFunction = new SqlFunction(datasource,"select count(*) from zm_test_sjdbc"); sqlFunction.compile(); return sqlFunction.run(); } }
应用场景:
获取满足条件下的结果条数。
如表总数,某种状态下数据条数。