?
Solved

Temporary table in java

Posted on 2014-04-16
7
Medium Priority
?
3,709 Views
Last Modified: 2014-04-21
I am writing a java code to which retrieve values from a big table and stores in some other tables.
here is my question i want to create a temp table using java code the column entries for that temp table is from the big table i mentioned
also I want to add new column to this temp table...

how can i achieve this with out effecting the database - is it possible to create temp table using java
also can i perform sql queries on such temp table

if i can effect the database I will create a view but I don't want to create any new table or view just for this one program
so is there a way for me to create a temporary view or table which can be used with in the program and will never exist once control comes out of program.
0
Comment
Question by:shragi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 36

Expert Comment

by:mccarl
ID: 40005643
This is not really the responsibility of Java. If you want to create a temporary table, that would be dependant on what type of database you are using. Having said that, most databases support temporary tables, so you should be able to do it. It's just that exactly how you do it will depend on the type of database. If you can tell us this information, I may be able to help further. Also can you tell us what you are currently using in Java to work with the database, ie. are you using JDBC, Spring, Hibernate, JPA, etc, etc?
0
 
LVL 37

Expert Comment

by:zzynx
ID: 40005958
>> i want to create a temp table using java code the column entries for that temp table is from the big table i mentioned
Why do you need that temp table?
>> also I want to add new column to this temp table...
Why? Since you also wrote:
>> temporary ... table which ... will never exist once control comes out of program

So you need part of the data of the big table + some extra inside the java program. That's all.
Why don't you query the data you need from the big table and keep that in memory (in a List or a Map)?
I just don't see it.
0
 

Author Comment

by:shragi
ID: 40007185
@zzynx the reason why I don't want to keep it in list or map or resultset is I want to query on that temp table which i want to create.... if i stored in any of the data structure you mentioned I cannot query on the results i mean i don't have flexibility to select the data i want....

@mccarl I am using sql server 2012 and using JDBC....
0
Basic Security of Your VPC

So, you’ve got this shiny new VPC and a fancy new application configured on your EC2 servers ready to go. This application is only accessible from your computer, which is great for security, but you need your users to be able to access it! So, what’s the easiest way to do this?

 

Author Comment

by:shragi
ID: 40007586
I found the below article which is close to what i want....but not exactly..
also I convinced my mgr to be able to create a temp table in DB for this program so my problem is fixed....all i do is store the data in the table during program and remove the data from table as process goes on....

http://www.javaworld.com/article/2075440/core-java/develop-a-generic-caching-service-to-improve-performance.html
0
 
LVL 37

Expert Comment

by:zzynx
ID: 40008307
>> I convinced my mgr to be able to create a temp table in DB for this program
Given you  need to query, I think that's the most evident solution too.
>> so my problem is fixed
Good to hear.
0
 
LVL 28

Accepted Solution

by:
dpearson earned 2000 total points
ID: 40010974
It sounds like you figured out a workaround, but you should at least be aware that "temp tables" are a fully supported database concept.

They exist just as long as the connection to the database exists.  When you break the connection, the table goes away.

You can read about the specifics of how SQL Server does this here:
http://www.codeproject.com/Articles/42553/Quick-Overview-Temporary-Tables-in-SQL-Server-2005

but the simple rule is you just add "#" to the front of the table name in your "CREATE TABLE" call (which you can happily send through the JDBC driver, just like any other statement - like a SELECT or UPDATE).

Here's a simple example, again for SQL Server:
http://www.sqlteam.com/article/temporary-tables

Hope that helps,

Doug
0
 

Author Comment

by:shragi
ID: 40012755
THanks Doug - that's helpful
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is about my first experience with programming Arduino.
The SignAloud Glove is capable of translating American Sign Language signs into text and audio.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Six Sigma Control Plans
Suggested Courses
Course of the Month8 days, 1 hour left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question