2

I am trying to create a temporary table inside of AWS redshift using the java SDK.

 // Redshift JDBC 4.1 driver: com.amazon.redshift.jdbc41.Driver
 String command = "CREATE TABLE test (FirstName varchar(255));"
 Class.forName("com.amazon.redshift.jdbc41.Driver");
 conn = DriverManager.getConnection(dbURL, props);
 stmt = conn.createStatement();
 ResultSet rs = stmt.executeQuery(command);

When running this code the table is created successfully but on the return, an error is thrown

com.amazon.dsi.dataengine.impl.DSISimpleRowCountResult cannot be cast to com.amazon.dsi.dataengine.interfaces.IResultSet

Everything will work if I use a command that returns something, such as

"Select * FROM test;" 
"SELECT * FROM test LIMIT 0;"

I didn't see any documentation for this problem in the AWS READMEs or other stack overflow questions for this problem. It seems to me that there is a special class in the driver for when nothing is returned from the statement that is not able to be cast to the ResultSet class.

The redshift driver version is 1.1.13.1013 .

Any help would be greatly appreciated!

cwiens
  • 21
  • 4

1 Answers1

2

I had the same problem. You can solve this easily. Instead of

stmt.executeQuery(command);

please try

stmt.execute(command);
holodoc
  • 77
  • 1
  • 11