I want to truncate a 2 tables using JDBC

I want to truncate a 2 tables using JDBC. Please help me. Send me the code snippet.

Thanks,
Ashok
gak2000Asked:
Who is Participating?
 
zzynxConnect With a Mentor Software engineerCommented:
>> using JDBC
execute the SQL command

         table truncate yourTableName
0
 
CEHJCommented:
What do you mean by 'truncate'?
0
 
zzynxSoftware engineerCommented:
Get rid of the data but not the table itself?
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

 
CEHJConnect With a Mentor Commented:
If you mean all data, here's an example:

http://javaalmanac.com/egs/java.sql/DeleteAllBasicTable.html
0
 
zzynxSoftware engineerCommented:
Voila! ;°)
0
 
TimYatesConnect With a Mentor Commented:
> 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
 
zzynxSoftware engineerCommented:
>>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
 
TimYatesCommented:
that's the fella ;-)
0
 
cjjcliffordConnect With a Mentor Commented:
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
 
jLasithaCommented:
YOu can use SQL INNER JOIN Statement
0
 
cjjcliffordCommented:
jLasitha - to do what exactly?
0
 
jLasithaCommented:
sorry .I got a wrong idea with TRUNCATE..INNER JOIN is not useful i think
0
 
zzynxSoftware engineerCommented:
My recommendation: split between zzynx, CEHJ, TimYates and cjjclifford
0
 
cjjcliffordCommented:
zzynx's recommendation sounds good to me...
0
 
zzynxSoftware engineerCommented:
Agree
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.