Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

I want to truncate a 2 tables using JDBC

Posted on 2004-09-15
18
Medium Priority
?
2,190 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 500 total points
ID: 12064415
>> using JDBC
execute the SQL command

         table truncate yourTableName
0
Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 500 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 500 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 500 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

721 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