1515 * keyed factory cache hits on every repeated call because the SQL text is
1616 * identical.
1717 * <p>
18- * Assumes a table exists :
18+ * Assumes the {@code trades} table the ingest examples write :
1919 * <pre>
20- * CREATE TABLE trades (ts TIMESTAMP, sym SYMBOL, price DOUBLE, qty LONG)
21- * TIMESTAMP(ts) PARTITION BY DAY WAL;
20+ * CREATE TABLE trades (
21+ * symbol SYMBOL, side SYMBOL, price DOUBLE, amount DOUBLE, timestamp TIMESTAMP
22+ * ) TIMESTAMP(timestamp) PARTITION BY DAY WAL;
2223 * </pre>
2324 */
2425public class BindParametersExample {
2526
2627 public static void main (String [] args ) throws InterruptedException {
2728 try (QuestDB db = QuestDB .connect ("ws::addr=localhost:9000;" )) {
2829
29- String sql = "SELECT ts, sym , price, qty FROM trades "
30- + "WHERE sym = $1 AND price >= $2 AND ts >= $3 LIMIT 1000" ;
30+ String sql = "SELECT timestamp, symbol , price, amount FROM trades "
31+ + "WHERE symbol = $1 AND price >= $2 AND timestamp >= $3 LIMIT 1000" ;
3132
3233 // Same SQL, three different parameter sets. Each call reuses the
3334 // compiled factory on the server side because the text is identical.
34- String [] symbols = {"AAPL " , "MSFT " , "GOOG " };
35+ String [] symbols = {"ETH-USD " , "BTC-USD " , "SOL-USD " };
3536 for (String symbol : symbols ) {
3637 System .out .println ("fetching trades for " + symbol );
3738 try {
@@ -55,11 +56,11 @@ private static final class PrintingHandler implements QwpColumnBatchHandler {
5556 @ Override
5657 public void onBatch (QwpColumnBatch batch ) {
5758 batch .forEachRow (row -> System .out .printf (
58- "ts =%d sym =%s price=%.4f qty=%d %n" ,
59+ "timestamp =%d symbol =%s price=%.4f amount=%.5f %n" ,
5960 row .getLongValue (0 ),
6061 row .getSymbol (1 ),
6162 row .getDoubleValue (2 ),
62- row .getLongValue (3 )
63+ row .getDoubleValue (3 )
6364 ));
6465 }
6566
@@ -70,7 +71,6 @@ public void onEnd(long totalRows) {
7071
7172 @ Override
7273 public void onError (byte status , String message ) {
73- System .err .println ("query failed: status=" + status + " msg=" + message );
7474 }
7575 }
7676}
0 commit comments