473,396 Members | 1,929 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Unable to select from temporary tables

Hi,

I'm trying to declare and use temporary tables. I have written the
following code in Java. Creating the tablespace (i can see the
tablespace created using the Control Center), the temporary table and
even inserting the values execute fine (even the executeUpdate while
inserting returns a positive number indicating that rows have been
inserted). However, when I select * from the temporary table, 0 rows
are returned and the while loop is never entered. Any ideas why this is
happening?? Is it some configuration of my database?
Thanks in advance! Any help would be greatly appreciated... :)

==============================
import java.sql.*;

public class TempTableTest {

public static void main(String[] args) {
try {

Class.forName("COM.ibm.db2.jdbc.app.DB2Driver").ne wInstance();
String machine = "jdbc:db2:pmi";
String userName = "db2admin";
String password = "somepassword";
Connection conn =
DriverManager.getConnection(machine,userName, password);

Statement stmt = conn.createStatement();
stmt.executeUpdate("CREATE USER TEMPORARY TABLESPACE usertemp1 " +
" MANAGED BY SYSTEM " + " USING ('usertemp')");

stmt.executeUpdate("DECLARE GLOBAL TEMPORARY TABLE temptb1 " +
" LIKE mantest_featsum " +
" NOT LOGGED " +
" IN usertemp1");

stmt.executeUpdate(
"INSERT INTO session.temptb1 " +
"(SELECT
slidebarcode,total,gp2count,gp3count,gp5count,gp7c ount,gp9count FROM
mantest_featsum)");
ResultSet rs = stmt.executeQuery("SELECT * FROM session.temptb1");

while (rs.next())//Fetch a row of data
{
rs.getInt(2);
}
stmt.close();
conn.close();

}
catch (Exception e) {
System.out.println(e.getMessage());
}

}
}

Nov 12 '05 #1
2 2434
Check out the ON COMMIT PRESERVE ROWS option, or turn auto-commit off.

Miro

Nov 12 '05 #2
Andy S. wrote:
Hi,

I'm trying to declare and use temporary tables. I have written the
following code in Java. Creating the tablespace (i can see the
tablespace created using the Control Center), the temporary table and
even inserting the values execute fine (even the executeUpdate while
inserting returns a positive number indicating that rows have been
inserted). However, when I select * from the temporary table, 0 rows
are returned and the while loop is never entered. Any ideas why this is
happening?? Is it some configuration of my database?

<snip>
By default global temporray tables are defined ON COMMIT DELETE ROWS.
So if your client does autocommit all the insret work is in vain.
Try:
DECLARE GLOBAL .... ON COMMIT PRESERVE ROWS
And see what happens.

Cheers
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Nov 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Paulo Andre Ortega Ribeiro | last post by:
I have a Microsoft SQL Server 7.0. I wrote a sql command that creates a temporary table with a ORDER BY clause. When a execute a SELECT on this temporary table sometimes the result is ok, but...
2
by: mfyahya | last post by:
I have two tables, both containing an 'authors' column. Is there a way to get a unique list of authors from the two tables? I tried SELECT DISTINCT `authors` from `table1`, `table2`; but I got an...
2
by: Oliver Stratmann | last post by:
Hello All! I've got a problem with our DB2/NT 8.1.0 Database. The following SELECT on a big Table (2,5 Million rows) finishes with the Error "Unable to allocate new pages in table space...
3
by: vsaraog | last post by:
Hi everybody, I asked the following question but didn't get any reply. If anyone knows something about the problem, then please reply since I am really in a bind. Here is the question... I...
12
by: Doug Bell | last post by:
Hi, I am having problems trying to create a (temporary) DataTable from a selection from a DataGrid (dgOrders). dtOrdDetails is declared as a Public DataTable Sub is: Dim stFilter as String...
0
by: bazzer | last post by:
hey, i am using visual basic.net 2003 and have an ASP.NET webform application thats accessing a microsoft access 2003 database. i kept getting the following error when i tried to run it: ERROR ...
0
by: bazzer | last post by:
hey, im trying to access a microsoft access database from an ASP.NET web application in visual basic 2003.NET. i get the following error when i try running it: Server Error in...
6
by: Peter Nurse | last post by:
For reasons that are not relevant (though I explain them below *), I want, for all my users whatever privelige level, an SP which creates and inserts into a temporary table and then another SP...
6
Cintury
by: Cintury | last post by:
Hi all, I've developed a mobile application for windows mobile 5.0 that has been in use for a while (1 year and a couple of months). It was developed in visual studios 2005 with a back-end sql...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.