Groovy exports all table names in Database

Source: Internet
Author: User
Tags groovy script

In ant build file:

<Path id = "groovy. classpath">
<Fileset dir = "$ {java. Groovy}/lib">
<Include name = "*. Jar"/>
</Fileset>
<Fileset dir = "$ {java. Groovy}/embeddable">
<Include name = "*. Jar"/>
</Fileset>
<Pathelement location = "$ {Ext. libs. Oracle}/classes12.zip"/>
</Path>

<Taskdef name = "groovy"
Classname = "org. codehaus. Groovy. Ant. Groovy"
Classpathref = "groovy. classpath"/>

<Target name = "export. schema. to. File">
<Groovy src = "scripts/export. DB. Gy">
<Arg line = "$ {dB. url }$ {dB. schema. Owner }$ {dB. schema. Password }$ {filename}"/>
</Groovy>
</Target>

Groovy script:

Import groovy. SQL. SQL
Import oracle. JDBC. oracledriver

Println "DB. url:" + ARGs [0]
Println "DB. schema. ownver:" + ARGs [1]
Println "filename:" + ARGs [3]

SQL = SQL. newinstance (ARGs [0], argS [1],
ARGs [2], "Oracle. JDBC. oracledriver ");

New file (ARGs [3]). Delete ()
New file (ARGs [3]). createnewfile ()
Def writer = new file (ARGs [3]). newwriter ()
SQL. eachrow ("select table_name from user_tables order by table_name ASC", {writer. writeline (it. table_name )});
Writer. Close ();

List A = []
New file (ARGs [3]). eachline {Line-> A. Add (line )}

Println ("Total number of tables:" + A. Size ());

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.