Hi,
Try the next example and follow the same way for your:
// Open the JDBC connection.
try {
Connection conn =
DriverManager.getConnection("jdbc:ignite:thin://127.0.0.1;user=user;password=password");
//remove user password if you don't have security
conn.createStatement().execute("CREATE TABLE IF NOT EXISTS
Person(\n" +
" id int,\n" +
" city_id int,\n" +
" name varchar,\n" +
" age int, \n" +
" company varchar,\n" +
" PRIMARY KEY (id, city_id)\n" +
") WITH
\"template=partitioned,backups=1,affinity_key=city_id, key_type=PersonKey,
value_type=Person\";"); //IMPORTANT add key_type and value_type
conn.createStatement().execute("INSERT INTO Person (id, name,
city_id) VALUES (1, 'John Doe1', 3);");
conn.createStatement().execute("INSERT INTO Person (id, name,
city_id) VALUES (2, 'John Doe2', 3);");
conn.createStatement().execute("INSERT INTO Person (id, name,
city_id) VALUES (3, 'John Doe3', 3);");
conn.createStatement().execute("INSERT INTO Person (id, name,
city_id) VALUES (4, 'John Doe4', 3);");
conn.createStatement().execute("INSERT INTO Person (id, name,
city_id) VALUES (5, 'John Doe5', 3);");
conn.createStatement().execute("INSERT INTO Person (id, name,
city_id) VALUES (6, 'John Doe6', 3);");
conn.createStatement().execute("INSERT INTO Person (id, name,
city_id) VALUES (7, 'John Doe7', 3);");
conn.close();
BinaryObject key = ignite.binary().builder("PersonKey") //same
as in key type
.setField("id", 1)
.setField("city_id", 3)
.build();
IgniteCache<BinaryObject, BinaryObject> cache1 =
ignite.getOrCreateCache("SQL_PUBLIC_PERSON").withKeepBinary();
BinaryObject value = cache1.get(key);
System.out.println("Name is " + value.field("name"));
}
catch (SQLException e) {
e.printStackTrace();
Output is:
Name is John Doe1
BR,
Andrei
--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/