Solved

I want to truncate a 2 tables using JDBC

Posted on 2004-09-15
18
2,187 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
[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
  • 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
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
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

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

In this post we will learn different types of Android Layout and some basics of an Android App.
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 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…
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:
Suggested Courses

623 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