Solved

Temporary table in java

Posted on 2014-04-16
7
2,633 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
This is about my first experience with programming Arduino.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

743 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

10 Experts available now in Live!

Get 1:1 Help Now