[ https://issues.apache.org/jira/browse/CASSANDRA-3052?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13087995#comment-13087995 ]
Rick Shaw commented on CASSANDRA-3052: -------------------------------------- The spec implies that {{executeUpdate()}} is the correct method for CQL/SQL commands like {{CREATE, INSERT,UPDATE,DELETE}}. It also implies that the check is to be done on the returned result. In the case of {{executeQuery()}} an {{SQLException}} should be thrown if a {{ResultSet}} is not returned by the server. In the case of {{executeUpdate()}} return an error if a {{int}} update count is not returned. We have an inconsistent solution in place and I'm currently working on a patch. > CQL: ResultSet.next() gives NPE when run after an INSERT or CREATE statement > ---------------------------------------------------------------------------- > > Key: CASSANDRA-3052 > URL: https://issues.apache.org/jira/browse/CASSANDRA-3052 > Project: Cassandra > Issue Type: Bug > Reporter: Cathy Daw > Labels: cql > > This test script used to work until I upgraded the jdbc driver to 1.0.4. > *CQL 1.0.4*: apache-cassandra-cql-1.0.4-SNAPSHOT.jar build at revision 1158979 > *Repro Script*: > * drop in test directory, change package declaration and run: ant test > -Dtest.name=resultSetNPE > * The script gives you a NullPointerException when you uncomment out the > following lines after a CREATE or INSERT statement. > {code} > colCount = res.getMetaData().getColumnCount(); > res.next(); > {code} > * Please note that there is no need to comment out those lines if a SELECT > statement was run prior. > {code} > package com.datastax.bugs; > import java.sql.DriverManager; > import java.sql.Connection; > import java.sql.ResultSet; > import java.sql.SQLException; > import java.sql.Statement; > import org.junit.Test; > public class resultSetNPE { > > @Test > public void createKS() throws Exception { > Connection initConn = null; > Connection connection = null; > ResultSet res; > Statement stmt; > int colCount = 0; > > Class.forName("org.apache.cassandra.cql.jdbc.CassandraDriver"); > > // Check create keyspace > initConn = > DriverManager.getConnection("jdbc:cassandra://127.0.0.1:9160/default"); > stmt = initConn.createStatement(); > try { > System.out.println("Running DROP KS Statement"); > res = stmt.executeQuery("DROP KEYSPACE ks1"); > // res.next(); > > } catch (SQLException e) { > if (e.getMessage().startsWith("Keyspace does not exist")) > { > // Do nothing - this just means you tried to drop something > that was not there. > // res = stmt.executeQuery("CREATE KEYSPACE ks1 with > strategy_class = 'org.apache.cassandra.locator.SimpleStrategy' and > strategy_options:replication_factor=1"); > } > } > > System.out.println("Running CREATE KS Statement"); > res = stmt.executeQuery("CREATE KEYSPACE ks1 with strategy_class = > 'org.apache.cassandra.locator.SimpleStrategy' and > strategy_options:replication_factor=1"); > // res.next(); > initConn.close(); > } > > @Test > public void createCF() throws Exception > { > Class.forName("org.apache.cassandra.cql.jdbc.CassandraDriver"); > int colCount = 0; > Connection connection = > DriverManager.getConnection("jdbc:cassandra://127.0.0.1:9160/ks1"); > Statement stmt = connection.createStatement(); > System.out.print("Running CREATE CF Statement"); > ResultSet res = stmt.executeQuery("CREATE COLUMNFAMILY users (KEY > varchar PRIMARY KEY, password varchar, gender varchar, session_token varchar, > state varchar, birth_year bigint)"); > > //colCount = res.getMetaData().getColumnCount(); > System.out.println(" -- Column Count: " + colCount); > //res.next(); > > connection.close(); > } > > @Test > public void simpleSelect() throws Exception > { > Class.forName("org.apache.cassandra.cql.jdbc.CassandraDriver"); > int colCount = 0; > Connection connection = > DriverManager.getConnection("jdbc:cassandra://127.0.0.1:9160/ks1"); > Statement stmt = connection.createStatement(); > > System.out.print("Running INSERT Statement"); > ResultSet res = stmt.executeQuery("INSERT INTO users (KEY, password) > VALUES ('user1', 'ch@nge')"); > //colCount = res.getMetaData().getColumnCount(); > System.out.println(" -- Column Count: " + colCount); > //res.next(); > > System.out.print("Running SELECT Statement"); > res = stmt.executeQuery("SELECT KEY, gender, state FROM users"); > colCount = res.getMetaData().getColumnCount(); > System.out.println(" -- Column Count: " + colCount); > res.getRow(); > res.next(); > > connection.close(); > } > } > {code} -- This message is automatically generated by JIRA. For more information on JIRA, see: http://www.atlassian.com/software/jira