groovy-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ngalarn...@ABINITIO.COM
Subject Re: Oracle Insert Data from one table to another table using Groovy
Date Tue, 26 Jul 2016 11:54:06 GMT
The notation $row is for use inside a string (called string 
interpolation).

Try changing your sql.executeInsert line to:

        sql.executeInsert "INSERT INTO A (ID, Name) VALUES 
($row.ID,$row.Name)"

See: 
http://docs.groovy-lang.org/latest/html/documentation/index.html#_string_interpolation



From:   GroovyBeginner <groovybeginner@gmail.com>
To:     dev@groovy.incubator.apache.org, 
Date:   07/26/2016 02:46 AM
Subject:        Oracle Insert Data from one table to another table using 
Groovy



I have a requirement of inserting the data from table A into table B and 
am
using Oracle database. My condition is am going to insert only those 
records
which are not present in table B and am facing an issue of retrieving the
current row column values. Here is the code am trying.

    import groovy.sql.Sql;
    import java.sql.ResultSet;
    import java.util.Properties;
 
    sql = 
Sql.newInstance("jdbc:oracle:thin:@localhost:1521:XE","username",
"password", "oracle.jdbc.driver.OracleDriver")
        sql.query("select ID, NAME from A where ID not in (select id from
B)") { 
       row-> while(row.next()) {
        sql.executeInsert "INSERT INTO A (ID, Name) VALUES ("+$row.ID"+,+"
$row.Name+")"
    }
    }

and am facing issue `No such property: $row`. Kindly suggest me where am
going wrong and also is there any better approach of doing this in terms 
of
security and performance.



--
View this message in context: 
http://groovy.329449.n5.nabble.com/Oracle-Insert-Data-from-one-table-to-another-table-using-Groovy-tp5734285.html

Sent from the Groovy Dev mailing list archive at Nabble.com.



 
NOTICE from Ab Initio: This email (including any attachments) may contain 
information that is subject to confidentiality obligations or is legally 
privileged, and sender does not waive confidentiality or privilege. If 
received in error, please notify the sender, delete this email, and make 
no further use, disclosure, or distribution. 
Mime
View raw message