Here you can find the source of convertCount(Object obj)
Parameter | Description |
---|---|
obj | Object |
public static int convertCount(Object obj)
//package com.java2s; /*/* ww w . jav a 2 s.c om*/ * Copyright (c) 2008-2011 Simon Ritchie. * All rights reserved. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see http://www.gnu.org/licenses/>. */ import java.math.*; public class Main { /** * This method safely converts the result of a SELECT COUNT(*) to an int. * * @param obj Object * @return int */ public static int convertCount(Object obj) { if (obj instanceof Integer) { return (Integer) obj; } else if (obj instanceof Long) { return ((Long) obj).intValue(); } else if (obj instanceof BigDecimal) { return ((BigDecimal) obj).intValue(); } throw new RuntimeException("Cannot convert type " + obj.getClass() + " to an int"); } }