I ended up using a script in the layout template to query the database at generation time directly. Groovy sql didn't work because I kept getting errors on the import (despite the jar being in the declarations of the project, in the <web-inf> directory, etc.
Here is the code in the script, including how to get the value onto the output html:
<%
import java.sql.Connection
import java.sql.DriverManager
import java.sql.ResultSet
import java.sql.Statement
import javax.sql.DataSource
import org.apache.derby.drda.NetworkServerControl;
def signOid = unit["SignId"]
Class.forName("org.apache.derby.jdbc.ClientDriver");
NetworkServerControl serverControl = new NetworkServerControl(InetAddress.getByName("localhost"),1527);
serverControl.start (null);
Connection conn = DriverManager.getConnection('jdbc:derby://localhost:1527/StigmergyDb;password=user');
def sql = "SELECT COUNT(Value) FROM CONTRIBUTION WHERE Sign_Oid = " + signOid;
Statement stmt = conn.createStatement();
ResultSet options = stmt.executeQuery(sql);
options.next();
def optionCount = 0
def queryError = ""
try {
optionCount = options.getInt(1);
} catch (Exception e) {
optionCount = -1;
queryError = e.toString();
}
setHTMLOutput()
%>
// Here is how to output the count outside of the groovy script.
// The provided WebRatio example shows already how to use the variable
// value in groovy conditions
option Count = <%= optionCount%>