1
votes

I have created an Ignite cache "contact" and added "Person" object to it. When I use Ignite JDBC Client mode I am able to query this cache. But when I implement JDBC Thin Client, it says that the table Person does not exist. I tried the query this way:

Select * from Person

Select * from contact.Person

Both did not work with Thin Client. I am using Ignite 2.1. I appreciate your help as how to query an existing cache using Thin Client. Thank you.

Cache Configuration in default-config.xml

    <bean id="ignite.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
        <!-- Enabling Apache Ignite Persistent Store. -->
    <property name="persistentStoreConfiguration">
            <bean class="org.apache.ignite.configuration.PersistentStoreConfiguration"/>
        </property>

        <property name="binaryConfiguration">
            <bean class="org.apache.ignite.configuration.BinaryConfiguration">
                <property name="compactFooter" value="false"/>
            </bean>
        </property>

        <property name="memoryConfiguration">
            <bean class="org.apache.ignite.configuration.MemoryConfiguration">
                <!-- Setting the page size to 4 KB -->
                <property name="pageSize" value="#{4 * 1024}"/>
            </bean>
        </property>
        <!-- Explicitly configure TCP discovery SPI to provide a list of initial nodes. -->
        <property name="discoverySpi">
            <bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">
                <property name="ipFinder">
                    <bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.multicast.TcpDiscoveryMulticastIpFinder">
                        <property name="addresses">
                            <list>
                                <!-- In distributed environment, replace with actual host IP address. -->
                                <value>127.0.0.1:55500..55502</value>
                            </list>
                        </property>
                    </bean>
                </property>
            </bean>
        </property>
    </bean>
</beans>

Cache Configuration in the Server Side of the Code

CacheConfiguration<Long, Person> cc = new CacheConfiguration<>(cacheName);            
    cc.setCacheMode(CacheMode.REPLICATED);
    cc.setRebalanceMode(CacheRebalanceMode.ASYNC);
    cc.setIndexedTypes(Long.class, Person.class);
    cache = ignite.getOrCreateCache(cc);

Thin Client JDBC URL

 Class.forName("org.apache.ignite.IgniteJdbcThinDriver");
            // Open the JDBC connection.
            Connection conn = DriverManager.getConnection("jdbc:ignite:thin://192.168.1.111:10800");

            Statement st = conn.createStatement();
1
Could you share your cache configuration and jdbc connection string?Denis
Denis, please see the cache configuration and JDBC URL. Thanks for your help.Sam
Hi Denis, do you have any solution that you recommend for this? Thank you.Sam

1 Answers

2
votes

If you want to query data from an existing cache using SQL, you should specify an SQL schema in the cache configuration. Add the following code before the cache creation:

cc.setSqlSchema("PUBLIC");

Note that you have persistence configured, so when you do ignite.getOrCreateCache(cc); the new configuration won't be applied, if a cache with this name is already persisted. You should, for example, remove persistence data or use createCache(...) method instead.