Copy db table from one server to another server using groovy -
is there easy way query data 1 server (select * table_abc) , insert result different server (insert table_abc) ? both server using eg. db2, oracle etc. , tables containing various datatyps (varchar, varchar bitdata, binary blobs etc.)
cheers lza
here worked me...
import groovy.sql.sql // establish connections //progress openedge db connection def db1 = [url:'jdbc:datadirect:openedge://yourservername:20007; databasename=demo;', user:'user1', password:'', driver:'com.ddtek.jdbc.openedge.openedgedriver'] def sql1 = sql.newinstance(db1.url, db1.user, db1.password, db1.driver) //sql connection (on local machine) def db2 = [url:'jdbc:sqlserver://localhost;databasename=test;', user:'sa', password:'abc123', driver:'com.microsoft.sqlserver.jdbc.sqlserverdriver'] def sql2 = sql.newinstance(db2.url, db2.user, db2.password, db2.driver) // delete stale data in table 'newpersons' sql2.execute("delete newpersons region='1'") //get data sql1 connection sql1.eachrow("select distinct rtrim(first) firstname, rtrim(last) lastname pub.persons reg ='1'") { //for each row of sql1 connection insert record sql2 connection row -> while (row.next()) sql2.execute("insert newpersons(firstn, lastn) values ($row.firstname, $row.lastname)") }
Comments
Post a Comment