Juergen
17 years agoOccasional Contributor
Groovy Script SQL - Problems with the assignment of variables
I have the following problem I liked to select from a data bank a Sequence TEST_CASE_ID_SEQ and write this afterwards
in another table. Unfortunately, the handing over of the variable TEST_CASE_ID_SEQ into the variable TEST_CASE_ID does not work.
However, I get only the value 'null' I have written the following script.
What do I make wrong ??
##########################
import java.sql.Connection
import java.sql.DriverManager
import javax.sql.DataSource
import groovy.sql.Sql
import oracle.jdbc.driver.OracleTypes
import groovy.sql.DataSet
def driver = oracle.jdbc.driver.OracleDriver
def sql = Sql.newInstance ('jdbc:oracle:thin:pt_xxx/pt_xxx@localhost:31521:pt_xxx')
def TEST_CASE_ID_SEQ
def TEST_CASE_ID
//READ next Value of TEST_CASE_ID_SEQ
TEST_CASE_ID = sql.eachRow("SELECT TEST_CASE_ID_SEQ.nextval as TEST_CASE_ID_SEQ from dual")
{
}
println TEST_CASE_ID
// result null
//Write Value TEST_CASE_ID
//TEST_CASE_ID = "2345"
sql.execute("Insert into log TEST_CASE_ID values (?)", [TEST_CASE_ID])
#####################
Thanks and best regards
Juergen
in another table. Unfortunately, the handing over of the variable TEST_CASE_ID_SEQ into the variable TEST_CASE_ID does not work.
However, I get only the value 'null' I have written the following script.
What do I make wrong ??
##########################
import java.sql.Connection
import java.sql.DriverManager
import javax.sql.DataSource
import groovy.sql.Sql
import oracle.jdbc.driver.OracleTypes
import groovy.sql.DataSet
def driver = oracle.jdbc.driver.OracleDriver
def sql = Sql.newInstance ('jdbc:oracle:thin:pt_xxx/pt_xxx@localhost:31521:pt_xxx')
def TEST_CASE_ID_SEQ
def TEST_CASE_ID
//READ next Value of TEST_CASE_ID_SEQ
TEST_CASE_ID = sql.eachRow("SELECT TEST_CASE_ID_SEQ.nextval as TEST_CASE_ID_SEQ from dual")
{
}
println TEST_CASE_ID
// result null
//Write Value TEST_CASE_ID
//TEST_CASE_ID = "2345"
sql.execute("Insert into log TEST_CASE_ID values (?)", [TEST_CASE_ID])
#####################
Thanks and best regards
Juergen