Solved

I want to truncate a 2 tables using JDBC

Posted on 2004-09-15
18
2,185 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
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

Industry Leaders: 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

Suggested Solutions

Title # Comments Views Activity
SequenceInputStream example 3 37
Eclipse with various Java releases 7 85
What browser will run Java? 7 171
Java List 4 76
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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…
The viewer will learn how to implement Singleton Design Pattern in Java.

732 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