You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by gunman524 <gu...@126.com> on 2017/11/15 05:44:14 UTC

Can JAVA API SqlQuery query a cache create by SQL DDL?

Hi guys,

I use JDBC client driver to create a table,like:

stmt.executeUpdate("CREATE TABLE IF NOT EXISTS person ( id int,orgId LONG,
name VARCHAR, salary LONG ,PRIMARY KEY (id)) WITH \"backups=1,
affinityKey=id\"");

Could I use SqlQuery API to query this cache? I tried this way but does not
work

IgniteCache<Object, Person> cache =
ignite.cache("SQL_PUBLIC_PERSON").withKeepBinary();
        SqlQuery sql = new SqlQuery("SQL_PUBLIC_PERSON","id >? and id <?");

        try (QueryCursor<Map.Entry&lt;Object, BinaryObject>> cursor =
cache.query(sql.setArgs(5,10))) {
            for (Map.Entry<Object, BinaryObject> e : cursor)
                System.out.println(e.getValue().toString());
        }

Thanks



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/

Re: Can JAVA API SqlQuery query a cache create by SQL DDL?

Posted by gunman524 <gu...@126.com>.
vkulichenko, thanks for your advice。 It works, by setting value_type=person
during DDL, then running 
        SqlQuery sql = new SqlQuery("person","id >? and id <?");  can got
the cache!

Many thanks!




--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/

Re: Can JAVA API SqlQuery query a cache create by SQL DDL?

Posted by vkulichenko <va...@gmail.com>.
Hi,

You should specify type name instead of cache name when creating the query:

SqlQuery sql = new SqlQuery("person","id >? and id <?");

If this doesn't help, please provide the exception it fails with.

-Val



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/