How to read data from Global Temp table in HanaDB?

176 Views Asked by At

I have started using Hana DB very recently and was told to use Global temp table for one of the use cases. I was exploring temp tables and found out that Hana Global temp tables can share the records in one session and metadata across different sessions. Now when I am trying to test this out, I am creating a connection and using same connection to insert and read records from DB. But to my surprise I am not able to fetch any data from temp table even when I am using same db connection.

I have started using Hana Global temp tables recently. Could you please explain what does "database session" mean?

I am using Hana JDBC client and I have created a connection to Hana DB, now using this connection I am able to write to temp table but using the same connection I am not able to fetch the data from temp table. I am not disposing connection or for that matter I am not doing anything in between read and write operation but still I am not able to read the data from Global temp table.

Below is sample code

PreparedStatement ps = dbConnection.prepareStatement("Insert into TEST_SCHEMA.TMP_BA_COND values(1, null, 2)");
System.out.println("Inserted? "+ ps.executeUpdate());

ps = dbConnection.prepareStatement("SELECT * FROM TEST_SCHEMA.TMP_BA_COND");
ResultSet rs  = ps.executeQuery();
System.out.println(rs.getMetaData().getColumnName(1)+ " ");

while(rs.next()) {
  System.out.println(rs.getString(1) + " ");
}

Above code, shows that insertion was successful and one record got inserted while Select statement is showing that there are no records in table.

0

There are 0 best solutions below