Last active
May 25, 2021 23:45
-
-
Save FernandoCutire/91db3f671373f015579f4aed24b5134c to your computer and use it in GitHub Desktop.
Ejercicio1.groovy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env groovy | |
import groovy.sql.Sql | |
import groovy.util.logging.* | |
import java.sql.SQLException | |
import org.apache.log4j.* | |
import BGUTPConexion | |
import BGUTPLogger | |
@Log4j | |
class Ejercicio1 { | |
static void main(String[] args) { | |
Logger log = BGUTPLogger.getLogger(this.getName()) | |
def String i_estudiante = args[0] | |
println "Estudiante: " + i_estudiante | |
def Sql sqlSample = Sql.newInstance(BGUTPConexion.getDataSource('dbSample')) | |
executeMySQL(sqlSample, i_estudiante) | |
} | |
static private void executeMySQL(Sql sqlSample, String i_estudiante) { | |
try { | |
sqlSample.eachRow ( "call sp_prueba_groovy (?)", [i_estudiante] ) | |
{itc -> | |
println itc.t_entrada + "~ID: " + itc.id + " ~DESCRIPCIÓN: " + itc.descripcion | |
} | |
}catch (SQLException sqlex){ | |
while (sqlex != null){ | |
log.error "executeMySQL SQL: ${sqlex.getErrorCode()} ${sqlex.getMessage()}" | |
sqlex = sqlex.getNextException() | |
} | |
System.exit(1) | |
}catch(Exception ex) { | |
log.error "executeMySQL: ${ex}" | |
System.exit(1) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment