wood burning stoves 2.0*
The moose likes JDBC and the fly likes Creating Temp table and querying it Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Creating Temp table and querying it" Watch "Creating Temp table and querying it" New topic
Author

Creating Temp table and querying it

Fawad Ali
Ranch Hand

Joined: Dec 28, 2009
Posts: 112
Hi All,
I want to search some data in a table which has almost 1 million records. I want to get the data from database and then want to store it in a temp table. Now if next time I need to take data, I will take it from temp table. Example would be.

In a table named people of 1 million records, I want to search for people from New york. Let say the result is 10000 and I want to show only 50 on page. So I will be using pagination for this. Now on next call I dont want to repeat the search, I want to take it from temp table.

How will I achieve this in JDBC and is it a good solution or not?

Thanks in advance.


Regards, Fawad Ali.
Software Engineer, Stafona Inc. - My Blog
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2841
    
  11

We have a nice discussion of that issue at PaginationOrPaging. Take a look at that, and let us know if you have any other questions.
Fawad Ali
Ranch Hand

Joined: Dec 28, 2009
Posts: 112
Thanks Greg,
I am gonna go through it.
Fawad Ali
Ranch Hand

Joined: Dec 28, 2009
Posts: 112
Hi Greg,
I went through that discussion. I want t0 achieve a temporary table idea. I am connected to postgreSQL, and I am implementing it in a web based project. I am facing the following problems.

1) The postgreSQL does not support global temporary tables. How can we achieve that? I have posted it on postgreSQL forums as well.
2) If I get the first point to working, I will still be confused. I need to clear few things about temporary tables before implementing those. In my application if I want to search for people from New york and insert rows to temp table named abc_temp. At the same time some other user comes onto that page and he wants to search for people from Washington DC and again the rows are inserted to abc-temp. My question here is that whether we will have tow different tables now differing on session id or the second user's temp table will over write the first user's temp table.

Thanks for your help.

Regards,
dirshah.
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2841
    
  11

I'm afraid my experience with Postgres is extremely limited. I know it supports views and even materialized views. It seems to me a snapshot materialized view might get you what you need.

However, that's all in the database. There are constant design battles between application developers and DBDs. I'm an application developer, so the dumber I can make the database layer, the better I like it. I'd either limit the query to the page of data you need, or bring the whole set of data into the user's session, and populate pages as needed from there. Each user has a different session, so they can be paging through different data sets without fear of trampling on each other. If you need multiple users to share data results, adding a second level cache is a good idea. ehcache is the one I'm most familiar with. It's the default cache for Hibernate, but it also works with plain JDBC.

Greg
Fawad Ali
Ranch Hand

Joined: Dec 28, 2009
Posts: 112
Hi Greg,
Thanks a lot man. Still sounds great. Can you suggest me with some better discussions on how to implement cashes?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Creating Temp table and querying it
 
Similar Threads
Merging Multiple Lists
Best practice to access large data from database
How to retrieve partial data in SQL Server ?
Comparing Temporary table with a huge database
Performance Problem?