// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.sql.*;

public class FuncOpt {
    private static final int N = 1000000;
    public static void main(String[] args) throws Exception {
        Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
        Connection con = DriverManager.getConnection("jdbc:sqlserver://localhost:8990;DatabaseName=Test", "sa", "");
        Statement stmt = con.createStatement();
        int nerr = 0;
        for(int i = 0; i < N; i++) {
            ResultSet rs = stmt.executeQuery("SELECT GETDATE(),GETDATE(),GETDATE(),GETDATE(),GETDATE()");
            while(rs.next()) {
                Timestamp ts1 = rs.getTimestamp(1);
                Timestamp ts2 = rs.getTimestamp(2);
                Timestamp ts3 = rs.getTimestamp(3);
                Timestamp ts4 = rs.getTimestamp(4);
                Timestamp ts5 = rs.getTimestamp(5);
                if(!ts1.equals(ts2) || !ts2.equals(ts3) || !ts3.equals(ts4) || !ts4.equals(ts5)) {
                    nerr++;
                }
            }
            rs.close();
        }
        con.close();
        System.out.println(nerr);
    }
}
