Created
May 26, 2021 00:19
-
-
Save FernandoCutire/d3d340361576fb4afb4b267f3feda7fc to your computer and use it in GitHub Desktop.
Ejercicio 2 banco general
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 Ejercicio2 { | |
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 insertAccount(Sql sqlSample, String i_estudiante, String productoId) { | |
try { | |
println "insertAccount ejecutandose" | |
sqlSample.call("call sp_insert_prueba_groovy ($i_estudiante,$productoId,${Sql.INTEGER} )") { | |
retorno -> | |
if (retorno != 0) { | |
log.error "insertAccount SQL: Error insertando ${i_estudiante}, Producto ${productoId}" | |
} | |
} | |
} catch (SQLException sqlex) { | |
while (sqlex != null) { | |
log.error "insertAccount SQL: ${sqlex.getErrorCode()} ${sqlex.getMessage()}" | |
sqlex = sqlex.getNextException() | |
} | |
System.exit(1) | |
} catch (Exception ex) { | |
log.error "insertAccount: ${ex}" | |
System.exit(1) | |
} | |
} | |
static private void executeMySQL(Sql sqlSample, String i_estudiante) { | |
try { | |
sqlSample.eachRow("call sp_prueba_groovy (?)", [i_estudiante]) { | |
itc -> | |
// Llamando la función | |
insertAccount(sqlSample, i_estudiante, itc.id) | |
} | |
} 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