Here you can find the source of getSize2()
public static int getSize2() throws SQLException, IOException, ClassNotFoundException
//package com.java2s; //License from project: Apache License import java.io.IOException; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; public class Main { private static String protocol = "jdbc:derby:"; private static String dbName = "db"; public static int getSize2() throws SQLException, IOException, ClassNotFoundException { Connection conn = DriverManager.getConnection(protocol + dbName + ";create=true"); String sql = "select count(*) from whore2"; PreparedStatement ps = conn.prepareStatement(sql); ResultSet rs = ps.executeQuery(); rs.next();// ww w .j ava2 s. c o m int id = rs.getInt(1); rs.close(); ps.close(); conn.close(); return id; } }