Java DataSource getProductAllCount(DataSource ds, String key, String sql_allcount)

Here you can find the source of getProductAllCount(DataSource ds, String key, String sql_allcount)

Description

get Product All Count

License

Apache License

Declaration

public static int getProductAllCount(DataSource ds, String key, String sql_allcount) throws Exception 

Method Source Code


//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;

    }
}

Related

  1. getDataSourceCache(String hostName)
  2. getDBConnection(DataSource dataSource)
  3. getGlobalVariable(DataSource dataSource, String variable)
  4. getJdbcUrlFromDataSource(DataSource dataSource)
  5. getJNDIConnectionByContainer(String dataSource)
  6. getSchemaSeparator(DataSource dataSource)
  7. getTableColumnCount(DataSource dataSource, String selectedTable)
  8. getTables(DataSource datasource)
  9. hasTable(DataSource ds, String table)