Solved

I want to truncate a 2 tables using JDBC

Posted on 2004-09-15
18
2,176 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
 
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
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

Highfive Gives IT Their Time Back

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!

Join & Write a Comment

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

758 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