Rodrigo Graciano
02/07/2021, 8:49 PMval engine = ScriptEngineManager().getEngineByExtension("main.kts")!!
engine.put("jdbcTemplate",jdbcTemplate)
engine.eval("""@file:Import("/test.kts")""".trimIndent())
From the test.kts script
val template = bindings.get("jdbcTemplate")
ilya.chernikov
02/08/2021, 9:10 PMbindings
too. See e.g. tests and examples here: https://github.com/Kotlin/kotlin-script-examples/blob/master/jvm/jsr223/jsr223-simple/src/test/kotlin/org/jetbrains/kotlin/script/examples/jvm/jsr223/simple/test/simpleJsr223Test.kt#L32Rodrigo Graciano
02/08/2021, 10:01 PMRodrigo Graciano
02/08/2021, 10:02 PMval count = jdbcTemplate.queryForObject("Select count(*) from billionaires", Int::class.java)
println(count)
kt no issues, kts gives
Caused by: javax.script.ScriptException: Unresolved reference. None of the following candidates is applicable because of receiver type mismatch:
public inline fun <reified T> JdbcOperations.queryForObject(sql: String): TypeVariable(T) defined in org.springframework.jdbc.core
public inline fun <reified T> JdbcOperations.queryForObject(sql: String, args: Array<out Any>): TypeVariable(T)? defined in org.springframework.jdbc.core
public inline fun <reified T> JdbcOperations.queryForObject(sql: String, vararg args: Any, crossinline function: (ResultSet, Int) -> TypeVariable(T)): TypeVariable(T) defined in org.springframework.jdbc.core
public inline fun <reified T> JdbcOperations.queryForObject(sql: String, args: Array<out Any>, argTypes: IntArray): TypeVariable(T)? defined in org.springframework.jdbc.core
Rodrigo Graciano
02/09/2021, 1:16 AMval selectStmt: Statement = con.createStatement()
val rs: ResultSet = selectStmt
.executeQuery("Select name, id from billionaires")
while (rs.next()){
println(rs.getString(1))
println(rs.getLong(2))
}