package
com.binarynovae.gsql;
import
groovy.sql.Sql;
"5432/binarynovae"
,
"postgres"
,
"admin"
,
"org.postgresql.Driver"
)
println
"All Records:"
def
query =
"select * from person"
sql.eachRow query, {person->
println
person.name +
" "
+ person.person_id +
" "
+person.age
}
query =
"insert into person (name, person_id, age) values (?,?,?)"
def
name =
"Ryan"
def
age =
23
def
id =
1289367
sql.executeInsert query, [name, id, age];
println
"Inserted Record:"
query =
"select * from person where name = ?"
sql.eachRow(query,[name], {person->
println
person.name +
" "
+ person.person_id +
" "
+person.age
})
query =
"update person set age=? where name=?"
name =
"Ryan"
age =
30
sql.executeUpdate query, [age,name]
println
"Updated Record:"
query =
"select * from person where name = ?"
sql.eachRow(query,[name], {person->
println
person.name +
" "
+ person.person_id +
" "
+person.age
})
query =
"delete from person where name=?"
name =
"Ryan"
sql.execute query, [name]
println
"After deletion:"
query =
"select count(1) from person where name = ?"
sql.eachRow(query,[name], {row->
println
row[
0
]
})
No hay comentarios:
Publicar un comentario