Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- *
- *@author Codemonkey Junior
- */
- //compilar: groovyc Insercion.groovy
- //ejecutar: groovy Insercion.groovy 1 Ariel
- @Grapes(
- @Grab(group='org.jdbi', module='jdbi', version='2.77')
- )
- @GrabConfig(systemClassLoader=true)
- @Grab(group='mysql', module='mysql-connector-java', version='5.1.6')
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import org.skife.jdbi.v2.sqlobject.Bind;
- import org.skife.jdbi.v2.sqlobject.SqlQuery;
- import org.skife.jdbi.v2.sqlobject.customizers.RegisterMapper;
- import org.skife.jdbi.v2.DBI;
- import org.skife.jdbi.v2.Handle;
- import org.skife.jdbi.v2.tweak.*;
- import org.skife.jdbi.v2.*;
- import org.skife.jdbi.v2.util.*;
- class Insercion{
- static main(args) {
- int id
- String nombre=""
- DBI dbi = new DBI("jdbc:mysql://localhost:3306/test",
- "root",
- "5432");
- Handle h = dbi.open();
- if(!dbi.open().isInTransaction()){
- println "No esta realizando alguna transaccion";
- }
- //inserción de datos
- if(args.length > 0){
- id=Integer.parseInt(args[0]);
- nombre=args[1];
- try{
- h.execute("insert into cliente (id, name) values (?, ?)", id, nombre);
- }catch(Exception e){
- println "Error: "+ e.toString()
- }
- println "Datos insertados: (id= $id , nombre= $nombre)"
- }
- h.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement