Solved

I want to truncate a 2 tables using JDBC

Posted on 2004-09-15
18
2,182 Views
Last Modified: 2012-06-21
I want to truncate a 2 tables using JDBC. Please help me. Send me the code snippet.

Thanks,
Ashok
0
Comment
Question by:gak2000
  • 6
  • 3
  • 2
  • +2
18 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 12064373
What do you mean by 'truncate'?
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12064393
Get rid of the data but not the table itself?
0
 
LVL 37

Accepted Solution

by:
zzynx earned 125 total points
ID: 12064415
>> using JDBC
execute the SQL command

         table truncate yourTableName
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 125 total points
ID: 12064438
If you mean all data, here's an example:

http://javaalmanac.com/egs/java.sql/DeleteAllBasicTable.html
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12064470
Voila! ;°)
0
 
LVL 35

Assisted Solution

by:TimYates
TimYates earned 125 total points
ID: 12064753
> table truncate yourTableName

You mean;

  truncate table tablename

surely?

And TRUNCATE is better than DELETE FROM because it cleans indexes and suchlike (If I remember correctly from my Oracle days) ;-)

Tim
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12064979
>>You mean;
>>   truncate table tablename
http://www.1keydata.com/sql/sqltruncate.html

From the javaalmanac link CEHJ posted:
TRUNCATE is faster than DELETE since it does not generate rollback information,
does not fire any delete trigger, and does not record any information.
0
 
LVL 35

Expert Comment

by:TimYates
ID: 12064990
that's the fella ;-)
0
 
LVL 11

Assisted Solution

by:cjjclifford
cjjclifford earned 125 total points
ID: 12066702
actually, truncate is way faster since its actually DDL (Data Definition) that re-defines the table as empty. It cannot be done in several circumstances, particularily when there are foreign key constraints depending on entries in the table in question.
Also, using TRUNCATE with materialized views hanging off (in particular FAST REFRESH ON COMMIT) will break the materialized view.
If Truncate is not available, Oracle have published (on Metalink, DocID 1020306.6) a PL/SQL procedure that can be used with a DELETE statement, to commit every Nth row - this may be useful for you, but take care, using it could result in half performed deletes, especially if the application fails mid way (if you don't mind having data half deleted, or if your application can handle that, then its the way to go if you can't TRUNCATE!)

Cheers,
C.
0
 
LVL 1

Expert Comment

by:jLasitha
ID: 12071881
YOu can use SQL INNER JOIN Statement
0
 
LVL 11

Expert Comment

by:cjjclifford
ID: 12072925
jLasitha - to do what exactly?
0
 
LVL 1

Expert Comment

by:jLasitha
ID: 12072979
sorry .I got a wrong idea with TRUNCATE..INNER JOIN is not useful i think
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12284367
My recommendation: split between zzynx, CEHJ, TimYates and cjjclifford
0
 
LVL 11

Expert Comment

by:cjjclifford
ID: 12295639
zzynx's recommendation sounds good to me...
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12408395
Agree
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
hibernate example issues from command prompt 10 50
JavaFX TableView not displaying correctly 3 63
Bot application - advice 3 39
Java 8 to Java 6 8 22
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

820 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