Solved

Temporary table in java

Posted on 2014-04-16
7
2,719 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
7 Comments
 
LVL 35

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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

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 26

Accepted Solution

by:
dpearson earned 500 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to parse custom JSON to POJO java 4 55
JDeveloper 12c for 32 bit 4 68
java jdbc batch example 8 20
servlet example issue 6 30
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

911 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now