Return-Path: X-Original-To: apmail-cassandra-commits-archive@www.apache.org Delivered-To: apmail-cassandra-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 2CAAC7E78 for ; Sun, 21 Aug 2011 17:11:53 +0000 (UTC) Received: (qmail 95440 invoked by uid 500); 21 Aug 2011 17:11:53 -0000 Delivered-To: apmail-cassandra-commits-archive@cassandra.apache.org Received: (qmail 95406 invoked by uid 500); 21 Aug 2011 17:11:52 -0000 Mailing-List: contact commits-help@cassandra.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cassandra.apache.org Delivered-To: mailing list commits@cassandra.apache.org Received: (qmail 95397 invoked by uid 99); 21 Aug 2011 17:11:51 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 21 Aug 2011 17:11:51 +0000 X-ASF-Spam-Status: No, hits=-2000.9 required=5.0 tests=ALL_TRUSTED,RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.116] (HELO hel.zones.apache.org) (140.211.11.116) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 21 Aug 2011 17:11:48 +0000 Received: from hel.zones.apache.org (hel.zones.apache.org [140.211.11.116]) by hel.zones.apache.org (Postfix) with ESMTP id 42E03C7E63 for ; Sun, 21 Aug 2011 17:11:27 +0000 (UTC) Date: Sun, 21 Aug 2011 17:11:27 +0000 (UTC) From: "Rick Shaw (JIRA)" To: commits@cassandra.apache.org Message-ID: <870502346.56760.1313946687270.JavaMail.tomcat@hel.zones.apache.org> In-Reply-To: <1433846415.47532.1313631209461.JavaMail.tomcat@hel.zones.apache.org> Subject: [jira] [Updated] (CASSANDRA-3052) CQL: ResultSet.next() gives NPE when run after an INSERT or CREATE statement MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 X-Virus-Checked: Checked by ClamAV on apache.org [ https://issues.apache.org/jira/browse/CASSANDRA-3052?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Rick Shaw updated CASSANDRA-3052: --------------------------------- Attachment: statement-improper-result.txt Patch checks to make sure the intended result is returned from the various {{execute}} method variants. > 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 > Affects Versions: 0.8.4 > Reporter: Cathy Daw > Labels: JDBC, cql > Fix For: 0.8.5 > > Attachments: statement-improper-result.txt > > > 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