Here you can find the source of getcount()
public static int getcount()
//package com.java2s; //License from project: Apache License import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; public class Main { public static int getcount() { PreparedStatement statement = null; ResultSet rs = null;//from w ww .ja v a 2 s . co m Connection conn = getConnection(); try { String sql = "SELECT count(1) from user "; statement = conn.prepareStatement(sql); rs = statement.executeQuery(); int count = 0; if (rs.next()) { count = rs.getInt(1); } return count; } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { try { rs.close(); statement.close(); conn.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return 0; } public static Connection getConnection() { Connection conn = null; try { Class.forName("com.mysql.jdbc.Driver"); conn = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/desk", "root", "root"); return conn; } catch (Exception e) { e.printStackTrace(); return null; } } }