Advertisement
Guest User

Untitled

a guest
Apr 9th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. /**
  2. *
  3. *@author Codemonkey Junior
  4. */
  5. //compilar: groovyc Insercion.groovy
  6. //ejecutar: groovy Insercion.groovy 1 Ariel
  7.  
  8. @Grapes(
  9. @Grab(group='org.jdbi', module='jdbi', version='2.77')
  10. )
  11. @GrabConfig(systemClassLoader=true)
  12. @Grab(group='mysql', module='mysql-connector-java', version='5.1.6')
  13.  
  14. import java.sql.ResultSet;
  15. import java.sql.SQLException;
  16. import org.skife.jdbi.v2.sqlobject.Bind;
  17. import org.skife.jdbi.v2.sqlobject.SqlQuery;
  18. import org.skife.jdbi.v2.sqlobject.customizers.RegisterMapper;
  19. import org.skife.jdbi.v2.DBI;
  20. import org.skife.jdbi.v2.Handle;
  21. import org.skife.jdbi.v2.tweak.*;
  22. import org.skife.jdbi.v2.*;
  23. import org.skife.jdbi.v2.util.*;
  24.  
  25.  
  26.  
  27. class Insercion{
  28. static main(args) {
  29. int id
  30. String nombre=""
  31.  
  32. DBI dbi = new DBI("jdbc:mysql://localhost:3306/test",
  33. "root",
  34. "5432");
  35. Handle h = dbi.open();
  36. if(!dbi.open().isInTransaction()){
  37. println "No esta realizando alguna transaccion";
  38. }
  39.  
  40. //inserción de datos
  41. if(args.length > 0){
  42. id=Integer.parseInt(args[0]);
  43. nombre=args[1];
  44. try{
  45. h.execute("insert into cliente (id, name) values (?, ?)", id, nombre);
  46. }catch(Exception e){
  47. println "Error: "+ e.toString()
  48. }
  49. println "Datos insertados: (id= $id , nombre= $nombre)"
  50. }
  51. h.close();
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement