@@ -1013,6 +1013,29 @@ public Void run(TransactionContext transaction) throws Exception {
1013
1013
}
1014
1014
// [END spanner_dml_getting_started_insert]
1015
1015
1016
+ // [START spanner_query_with_parameter]
1017
+ static void queryWithParameter (DatabaseClient dbClient ) {
1018
+ Statement statement =
1019
+ Statement
1020
+ .newBuilder (
1021
+ "SELECT SingerId, FirstName, LastName\n "
1022
+ + "FROM Singers\n "
1023
+ + "WHERE LastName = @lastName" )
1024
+ .bind ("lastName" )
1025
+ .to ("Garcia" )
1026
+ .build ();
1027
+
1028
+ ResultSet resultSet = dbClient .singleUse ().executeQuery (statement );
1029
+ while (resultSet .next ()) {
1030
+ System .out .printf (
1031
+ "%d %s %s\n " ,
1032
+ resultSet .getLong ("SingerId" ),
1033
+ resultSet .getString ("FirstName" ),
1034
+ resultSet .getString ("LastName" ));
1035
+ }
1036
+ }
1037
+ // [END spanner_query_with_parameter]
1038
+
1016
1039
// [START spanner_dml_getting_started_update]
1017
1040
static void writeWithTransactionUsingDml (DatabaseClient dbClient ) {
1018
1041
dbClient
@@ -1229,6 +1252,9 @@ static void run(
1229
1252
case "writeusingdml" :
1230
1253
writeUsingDml (dbClient );
1231
1254
break ;
1255
+ case "querywithparameter" :
1256
+ queryWithParameter (dbClient );
1257
+ break ;
1232
1258
case "writewithtransactionusingdml" :
1233
1259
writeWithTransactionUsingDml (dbClient );
1234
1260
break ;
@@ -1286,6 +1312,7 @@ static void printUsageAndExit() {
1286
1312
System .err .println (" SpannerExample writeandreadusingdml my-instance example-db" );
1287
1313
System .err .println (" SpannerExample updateusingdmlwithstruct my-instance example-db" );
1288
1314
System .err .println (" SpannerExample writeusingdml my-instance example-db" );
1315
+ System .err .println (" SpannerExample queryWithParameter my-instance example-db" );
1289
1316
System .err .println (" SpannerExample writewithtransactionusingdml my-instance example-db" );
1290
1317
System .err .println (" SpannerExample updateusingpartitioneddml my-instance example-db" );
1291
1318
System .err .println (" SpannerExample deleteusingpartitioneddml my-instance example-db" );
0 commit comments