You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by Ivan Zeng <iv...@gmail.com> on 2017/03/16 18:46:32 UTC

create table via JDBC

Hi,

I am new to Ignite.  Could you tell me the right way to create a
cache, load data into cache, and then query the cache via JDBC?

I wrote the following code to create a table via JDBC.


    Class.forName("org.apache.ignite.IgniteJdbcDriver");
    con = DriverManager.getConnection (connectionURL)
    String create_sql = "CREATE TABLE Person " +
                  "(_key INTEGER PRIMARY KEY, " +
                  " name VARCHAR(255), " +
                  " age INTEGER);";
    Statement cstmt = con.createStatement();
    cstmt.executeQuery(create_sql);


But i got this error.

java.sql.SQLException: Failed to query Ignite.
at org.apache.ignite.internal.jdbc2.JdbcStatement.executeQuery(JdbcStatement.java:131)
at IgniteJDBC.main(IgniteJDBC.java:26)
Caused by: javax.cache.CacheException: Unsupported SQL statement:
CREATE TABLE Person (_key INTEGER PRIMARY KEY,  name VARCHAR(255),
age INTEGER)

Thanks so much
Ivan

Re: create table via JDBC

Posted by Denis Magda <dm...@apache.org>.
> I will dig into the example directory to see if I can find example
> where a cache is created and then fields are added dynamically.

It will be feasible to add new QueryEntity fields and indexes in a month or so once this ticket is completed:
https://issues.apache.org/jira/browse/IGNITE-4565 <https://issues.apache.org/jira/browse/IGNITE-4565>

For now you can define them only statically.

However, the lack of this feature doesn’t prevent you from putting objects into a cache with new objects' fields. You just won’t be able to query over these new fields using SQL queries until IGNITE-4565 gets merged.

—
Denis

> On Mar 16, 2017, at 5:28 PM, Ivan Zeng <iv...@gmail.com> wrote:
> 
> Thanks Denis.
> 
> I see that the example you gave use existing classes.  These classes
> will need to be defined ahead of time.
> 
> I will dig into the example directory to see if I can find example
> where a cache is created and then fields are added dynamically.
> 
> If you know of any of this example, please let me know.  Thank you so much.
> 
> Ivan
> 
> On Thu, Mar 16, 2017 at 4:47 PM, Denis Magda <dm...@apache.org> wrote:
>> Ivan,
>> 
>> You can refer to this example:
>> https://github.com/apache/ignite/blob/master/examples/src/main/java/org/apache/ignite/examples/datagrid/CacheQueryExample.java
>> 
>> Also there is a plenty of other useful examples available under the examples
>> directory of an Apache Ignite distribution. Just fish in it.
>> 
>> —
>> Denis
>> 
>> On Mar 16, 2017, at 4:25 PM, Ivan Zeng <iv...@gmail.com> wrote:
>> 
>> Hi Denis,
>> 
>> Thanks for the response.  Is there any sample code on how to use the
>> IgniteCache to create caches with different fields and load data into
>> the cache?
>> 
>> Thanks so much.
>> Ivan
>> 
>> On Thu, Mar 16, 2017 at 3:52 PM, Denis Magda <dm...@apache.org> wrote:
>> 
>> Hi Ivan,
>> 
>> Yes, caches can be created dynamically:
>> https://apacheignite.readme.io/docs/jcache#section-dynamic-cache
>> 
>> —
>> Denis
>> 
>> On Mar 16, 2017, at 3:28 PM, Ivan Zeng <iv...@gmail.com> wrote:
>> 
>> Hi Dmitriy,
>> 
>> Thanks for your reply.  I was able to load data into cache after
>> adding the QueryEntity in configuration. And I actually needed to
>> restart the server database to pick up the new configuration.  Is
>> there a way that I can create new cache without restarting the server?
>> 
>> Thank so much
>> Ivan
>> 
>> On Thu, Mar 16, 2017 at 1:24 PM, Dmitriy Setrakyan
>> <ds...@apache.org> wrote:
>> 
>> DDL commands are not supported in Ignite yet. However, in Ignite the table
>> will be created automatically if you define a class with @SqlQueryField
>> annotations or define a QueryEntity in configuration, as described here:
>> 
>> https://apacheignite.readme.io/docs/indexes
>> 
>> Starting with Ignite 2.0, planned in April, Ignite will support CREATE/DROP
>> INDEX command. Further it is planned that towards June/July Ignite will have
>> full DDL support, including CREATE/ALTER/DROP TABLE commands.
>> 
>> D.
>> 
>> On Thu, Mar 16, 2017 at 11:46 AM, Ivan Zeng <iv...@gmail.com> wrote:
>> 
>> 
>> Hi,
>> 
>> I am new to Ignite.  Could you tell me the right way to create a
>> cache, load data into cache, and then query the cache via JDBC?
>> 
>> I wrote the following code to create a table via JDBC.
>> 
>> 
>>  Class.forName("org.apache.ignite.IgniteJdbcDriver");
>>  con = DriverManager.getConnection (connectionURL)
>>  String create_sql = "CREATE TABLE Person " +
>>                "(_key INTEGER PRIMARY KEY, " +
>>                " name VARCHAR(255), " +
>>                " age INTEGER);";
>>  Statement cstmt = con.createStatement();
>>  cstmt.executeQuery(create_sql);
>> 
>> 
>> But i got this error.
>> 
>> java.sql.SQLException: Failed to query Ignite.
>> at
>> org.apache.ignite.internal.jdbc2.JdbcStatement.executeQuery(JdbcStatement.java:131)
>> at IgniteJDBC.main(IgniteJDBC.java:26)
>> Caused by: javax.cache.CacheException: Unsupported SQL statement:
>> CREATE TABLE Person (_key INTEGER PRIMARY KEY,  name VARCHAR(255),
>> age INTEGER)
>> 
>> Thanks so much
>> Ivan
>> 
>> 
>> 
>> 
>> 


Re: create table via JDBC

Posted by Ivan Zeng <iv...@gmail.com>.
Thanks Denis.

I see that the example you gave use existing classes.  These classes
will need to be defined ahead of time.

I will dig into the example directory to see if I can find example
where a cache is created and then fields are added dynamically.

If you know of any of this example, please let me know.  Thank you so much.

Ivan

On Thu, Mar 16, 2017 at 4:47 PM, Denis Magda <dm...@apache.org> wrote:
> Ivan,
>
> You can refer to this example:
> https://github.com/apache/ignite/blob/master/examples/src/main/java/org/apache/ignite/examples/datagrid/CacheQueryExample.java
>
> Also there is a plenty of other useful examples available under the examples
> directory of an Apache Ignite distribution. Just fish in it.
>
> —
> Denis
>
> On Mar 16, 2017, at 4:25 PM, Ivan Zeng <iv...@gmail.com> wrote:
>
> Hi Denis,
>
> Thanks for the response.  Is there any sample code on how to use the
> IgniteCache to create caches with different fields and load data into
> the cache?
>
> Thanks so much.
> Ivan
>
> On Thu, Mar 16, 2017 at 3:52 PM, Denis Magda <dm...@apache.org> wrote:
>
> Hi Ivan,
>
> Yes, caches can be created dynamically:
> https://apacheignite.readme.io/docs/jcache#section-dynamic-cache
>
> —
> Denis
>
> On Mar 16, 2017, at 3:28 PM, Ivan Zeng <iv...@gmail.com> wrote:
>
> Hi Dmitriy,
>
> Thanks for your reply.  I was able to load data into cache after
> adding the QueryEntity in configuration. And I actually needed to
> restart the server database to pick up the new configuration.  Is
> there a way that I can create new cache without restarting the server?
>
> Thank so much
> Ivan
>
> On Thu, Mar 16, 2017 at 1:24 PM, Dmitriy Setrakyan
> <ds...@apache.org> wrote:
>
> DDL commands are not supported in Ignite yet. However, in Ignite the table
> will be created automatically if you define a class with @SqlQueryField
> annotations or define a QueryEntity in configuration, as described here:
>
> https://apacheignite.readme.io/docs/indexes
>
> Starting with Ignite 2.0, planned in April, Ignite will support CREATE/DROP
> INDEX command. Further it is planned that towards June/July Ignite will have
> full DDL support, including CREATE/ALTER/DROP TABLE commands.
>
> D.
>
> On Thu, Mar 16, 2017 at 11:46 AM, Ivan Zeng <iv...@gmail.com> wrote:
>
>
> Hi,
>
> I am new to Ignite.  Could you tell me the right way to create a
> cache, load data into cache, and then query the cache via JDBC?
>
> I wrote the following code to create a table via JDBC.
>
>
>   Class.forName("org.apache.ignite.IgniteJdbcDriver");
>   con = DriverManager.getConnection (connectionURL)
>   String create_sql = "CREATE TABLE Person " +
>                 "(_key INTEGER PRIMARY KEY, " +
>                 " name VARCHAR(255), " +
>                 " age INTEGER);";
>   Statement cstmt = con.createStatement();
>   cstmt.executeQuery(create_sql);
>
>
> But i got this error.
>
> java.sql.SQLException: Failed to query Ignite.
> at
> org.apache.ignite.internal.jdbc2.JdbcStatement.executeQuery(JdbcStatement.java:131)
> at IgniteJDBC.main(IgniteJDBC.java:26)
> Caused by: javax.cache.CacheException: Unsupported SQL statement:
> CREATE TABLE Person (_key INTEGER PRIMARY KEY,  name VARCHAR(255),
> age INTEGER)
>
> Thanks so much
> Ivan
>
>
>
>
>

Re: create table via JDBC

Posted by Denis Magda <dm...@apache.org>.
Ivan,

You can refer to this example:
https://github.com/apache/ignite/blob/master/examples/src/main/java/org/apache/ignite/examples/datagrid/CacheQueryExample.java <https://github.com/apache/ignite/blob/master/examples/src/main/java/org/apache/ignite/examples/datagrid/CacheQueryExample.java>

Also there is a plenty of other useful examples available under the examples directory of an Apache Ignite distribution. Just fish in it.

—
Denis

> On Mar 16, 2017, at 4:25 PM, Ivan Zeng <iv...@gmail.com> wrote:
> 
> Hi Denis,
> 
> Thanks for the response.  Is there any sample code on how to use the
> IgniteCache to create caches with different fields and load data into
> the cache?
> 
> Thanks so much.
> Ivan
> 
> On Thu, Mar 16, 2017 at 3:52 PM, Denis Magda <dm...@apache.org> wrote:
>> Hi Ivan,
>> 
>> Yes, caches can be created dynamically:
>> https://apacheignite.readme.io/docs/jcache#section-dynamic-cache
>> 
>> —
>> Denis
>> 
>> On Mar 16, 2017, at 3:28 PM, Ivan Zeng <iv...@gmail.com> wrote:
>> 
>> Hi Dmitriy,
>> 
>> Thanks for your reply.  I was able to load data into cache after
>> adding the QueryEntity in configuration. And I actually needed to
>> restart the server database to pick up the new configuration.  Is
>> there a way that I can create new cache without restarting the server?
>> 
>> Thank so much
>> Ivan
>> 
>> On Thu, Mar 16, 2017 at 1:24 PM, Dmitriy Setrakyan
>> <ds...@apache.org> wrote:
>> 
>> DDL commands are not supported in Ignite yet. However, in Ignite the table
>> will be created automatically if you define a class with @SqlQueryField
>> annotations or define a QueryEntity in configuration, as described here:
>> 
>> https://apacheignite.readme.io/docs/indexes
>> 
>> Starting with Ignite 2.0, planned in April, Ignite will support CREATE/DROP
>> INDEX command. Further it is planned that towards June/July Ignite will have
>> full DDL support, including CREATE/ALTER/DROP TABLE commands.
>> 
>> D.
>> 
>> On Thu, Mar 16, 2017 at 11:46 AM, Ivan Zeng <iv...@gmail.com> wrote:
>> 
>> 
>> Hi,
>> 
>> I am new to Ignite.  Could you tell me the right way to create a
>> cache, load data into cache, and then query the cache via JDBC?
>> 
>> I wrote the following code to create a table via JDBC.
>> 
>> 
>>   Class.forName("org.apache.ignite.IgniteJdbcDriver");
>>   con = DriverManager.getConnection (connectionURL)
>>   String create_sql = "CREATE TABLE Person " +
>>                 "(_key INTEGER PRIMARY KEY, " +
>>                 " name VARCHAR(255), " +
>>                 " age INTEGER);";
>>   Statement cstmt = con.createStatement();
>>   cstmt.executeQuery(create_sql);
>> 
>> 
>> But i got this error.
>> 
>> java.sql.SQLException: Failed to query Ignite.
>> at
>> org.apache.ignite.internal.jdbc2.JdbcStatement.executeQuery(JdbcStatement.java:131)
>> at IgniteJDBC.main(IgniteJDBC.java:26)
>> Caused by: javax.cache.CacheException: Unsupported SQL statement:
>> CREATE TABLE Person (_key INTEGER PRIMARY KEY,  name VARCHAR(255),
>> age INTEGER)
>> 
>> Thanks so much
>> Ivan
>> 
>> 
>> 
>> 


Re: create table via JDBC

Posted by Ivan Zeng <iv...@gmail.com>.
Hi Denis,

Thanks for the response.  Is there any sample code on how to use the
IgniteCache to create caches with different fields and load data into
the cache?

Thanks so much.
Ivan

On Thu, Mar 16, 2017 at 3:52 PM, Denis Magda <dm...@apache.org> wrote:
> Hi Ivan,
>
> Yes, caches can be created dynamically:
> https://apacheignite.readme.io/docs/jcache#section-dynamic-cache
>
> —
> Denis
>
> On Mar 16, 2017, at 3:28 PM, Ivan Zeng <iv...@gmail.com> wrote:
>
> Hi Dmitriy,
>
> Thanks for your reply.  I was able to load data into cache after
> adding the QueryEntity in configuration. And I actually needed to
> restart the server database to pick up the new configuration.  Is
> there a way that I can create new cache without restarting the server?
>
> Thank so much
> Ivan
>
> On Thu, Mar 16, 2017 at 1:24 PM, Dmitriy Setrakyan
> <ds...@apache.org> wrote:
>
> DDL commands are not supported in Ignite yet. However, in Ignite the table
> will be created automatically if you define a class with @SqlQueryField
> annotations or define a QueryEntity in configuration, as described here:
>
> https://apacheignite.readme.io/docs/indexes
>
> Starting with Ignite 2.0, planned in April, Ignite will support CREATE/DROP
> INDEX command. Further it is planned that towards June/July Ignite will have
> full DDL support, including CREATE/ALTER/DROP TABLE commands.
>
> D.
>
> On Thu, Mar 16, 2017 at 11:46 AM, Ivan Zeng <iv...@gmail.com> wrote:
>
>
> Hi,
>
> I am new to Ignite.  Could you tell me the right way to create a
> cache, load data into cache, and then query the cache via JDBC?
>
> I wrote the following code to create a table via JDBC.
>
>
>    Class.forName("org.apache.ignite.IgniteJdbcDriver");
>    con = DriverManager.getConnection (connectionURL)
>    String create_sql = "CREATE TABLE Person " +
>                  "(_key INTEGER PRIMARY KEY, " +
>                  " name VARCHAR(255), " +
>                  " age INTEGER);";
>    Statement cstmt = con.createStatement();
>    cstmt.executeQuery(create_sql);
>
>
> But i got this error.
>
> java.sql.SQLException: Failed to query Ignite.
> at
> org.apache.ignite.internal.jdbc2.JdbcStatement.executeQuery(JdbcStatement.java:131)
> at IgniteJDBC.main(IgniteJDBC.java:26)
> Caused by: javax.cache.CacheException: Unsupported SQL statement:
> CREATE TABLE Person (_key INTEGER PRIMARY KEY,  name VARCHAR(255),
> age INTEGER)
>
> Thanks so much
> Ivan
>
>
>
>

Re: create table via JDBC

Posted by Denis Magda <dm...@apache.org>.
Hi Ivan,

Yes, caches can be created dynamically:
https://apacheignite.readme.io/docs/jcache#section-dynamic-cache <https://apacheignite.readme.io/docs/jcache#section-dynamic-cache>

—
Denis

> On Mar 16, 2017, at 3:28 PM, Ivan Zeng <iv...@gmail.com> wrote:
> 
> Hi Dmitriy,
> 
> Thanks for your reply.  I was able to load data into cache after
> adding the QueryEntity in configuration. And I actually needed to
> restart the server database to pick up the new configuration.  Is
> there a way that I can create new cache without restarting the server?
> 
> Thank so much
> Ivan
> 
> On Thu, Mar 16, 2017 at 1:24 PM, Dmitriy Setrakyan
> <ds...@apache.org> wrote:
>> DDL commands are not supported in Ignite yet. However, in Ignite the table
>> will be created automatically if you define a class with @SqlQueryField
>> annotations or define a QueryEntity in configuration, as described here:
>> 
>> https://apacheignite.readme.io/docs/indexes
>> 
>> Starting with Ignite 2.0, planned in April, Ignite will support CREATE/DROP
>> INDEX command. Further it is planned that towards June/July Ignite will have
>> full DDL support, including CREATE/ALTER/DROP TABLE commands.
>> 
>> D.
>> 
>> On Thu, Mar 16, 2017 at 11:46 AM, Ivan Zeng <iv...@gmail.com> wrote:
>>> 
>>> Hi,
>>> 
>>> I am new to Ignite.  Could you tell me the right way to create a
>>> cache, load data into cache, and then query the cache via JDBC?
>>> 
>>> I wrote the following code to create a table via JDBC.
>>> 
>>> 
>>>    Class.forName("org.apache.ignite.IgniteJdbcDriver");
>>>    con = DriverManager.getConnection (connectionURL)
>>>    String create_sql = "CREATE TABLE Person " +
>>>                  "(_key INTEGER PRIMARY KEY, " +
>>>                  " name VARCHAR(255), " +
>>>                  " age INTEGER);";
>>>    Statement cstmt = con.createStatement();
>>>    cstmt.executeQuery(create_sql);
>>> 
>>> 
>>> But i got this error.
>>> 
>>> java.sql.SQLException: Failed to query Ignite.
>>> at
>>> org.apache.ignite.internal.jdbc2.JdbcStatement.executeQuery(JdbcStatement.java:131)
>>> at IgniteJDBC.main(IgniteJDBC.java:26)
>>> Caused by: javax.cache.CacheException: Unsupported SQL statement:
>>> CREATE TABLE Person (_key INTEGER PRIMARY KEY,  name VARCHAR(255),
>>> age INTEGER)
>>> 
>>> Thanks so much
>>> Ivan
>> 
>> 


Re: create table via JDBC

Posted by Ivan Zeng <iv...@gmail.com>.
Hi Dmitriy,

Thanks for your reply.  I was able to load data into cache after
adding the QueryEntity in configuration. And I actually needed to
restart the server database to pick up the new configuration.  Is
there a way that I can create new cache without restarting the server?

Thank so much
Ivan

On Thu, Mar 16, 2017 at 1:24 PM, Dmitriy Setrakyan
<ds...@apache.org> wrote:
> DDL commands are not supported in Ignite yet. However, in Ignite the table
> will be created automatically if you define a class with @SqlQueryField
> annotations or define a QueryEntity in configuration, as described here:
>
> https://apacheignite.readme.io/docs/indexes
>
> Starting with Ignite 2.0, planned in April, Ignite will support CREATE/DROP
> INDEX command. Further it is planned that towards June/July Ignite will have
> full DDL support, including CREATE/ALTER/DROP TABLE commands.
>
> D.
>
> On Thu, Mar 16, 2017 at 11:46 AM, Ivan Zeng <iv...@gmail.com> wrote:
>>
>> Hi,
>>
>> I am new to Ignite.  Could you tell me the right way to create a
>> cache, load data into cache, and then query the cache via JDBC?
>>
>> I wrote the following code to create a table via JDBC.
>>
>>
>>     Class.forName("org.apache.ignite.IgniteJdbcDriver");
>>     con = DriverManager.getConnection (connectionURL)
>>     String create_sql = "CREATE TABLE Person " +
>>                   "(_key INTEGER PRIMARY KEY, " +
>>                   " name VARCHAR(255), " +
>>                   " age INTEGER);";
>>     Statement cstmt = con.createStatement();
>>     cstmt.executeQuery(create_sql);
>>
>>
>> But i got this error.
>>
>> java.sql.SQLException: Failed to query Ignite.
>> at
>> org.apache.ignite.internal.jdbc2.JdbcStatement.executeQuery(JdbcStatement.java:131)
>> at IgniteJDBC.main(IgniteJDBC.java:26)
>> Caused by: javax.cache.CacheException: Unsupported SQL statement:
>> CREATE TABLE Person (_key INTEGER PRIMARY KEY,  name VARCHAR(255),
>> age INTEGER)
>>
>> Thanks so much
>> Ivan
>
>

Re: create table via JDBC

Posted by Dmitriy Setrakyan <ds...@apache.org>.
DDL commands are not supported in Ignite yet. However, in Ignite the table
will be created automatically if you define a class with @SqlQueryField
annotations or define a QueryEntity in configuration, as described here:

https://apacheignite.readme.io/docs/indexes

Starting with Ignite 2.0, planned in April, Ignite will support CREATE/DROP
INDEX command. Further it is planned that towards June/July Ignite will
have full DDL support, including CREATE/ALTER/DROP TABLE commands.

D.

On Thu, Mar 16, 2017 at 11:46 AM, Ivan Zeng <iv...@gmail.com> wrote:

> Hi,
>
> I am new to Ignite.  Could you tell me the right way to create a
> cache, load data into cache, and then query the cache via JDBC?
>
> I wrote the following code to create a table via JDBC.
>
>
>     Class.forName("org.apache.ignite.IgniteJdbcDriver");
>     con = DriverManager.getConnection (connectionURL)
>     String create_sql = "CREATE TABLE Person " +
>                   "(_key INTEGER PRIMARY KEY, " +
>                   " name VARCHAR(255), " +
>                   " age INTEGER);";
>     Statement cstmt = con.createStatement();
>     cstmt.executeQuery(create_sql);
>
>
> But i got this error.
>
> java.sql.SQLException: Failed to query Ignite.
> at org.apache.ignite.internal.jdbc2.JdbcStatement.executeQuery(
> JdbcStatement.java:131)
> at IgniteJDBC.main(IgniteJDBC.java:26)
> Caused by: javax.cache.CacheException: Unsupported SQL statement:
> CREATE TABLE Person (_key INTEGER PRIMARY KEY,  name VARCHAR(255),
> age INTEGER)
>
> Thanks so much
> Ivan
>