Questions tagged [groovy-sql]

GroovySql is an API for the Groovy programming language

GroovySql uses closures and iterators to shift the burden of JDBC resource management from the developer to the Groovy framework.

27 questions
6
votes
1 answer

Runtime Exception Mocking groovy.sql in Spock

I've scoured around StackOverflow and Google for a while trying to find the right configuration/syntax for being able to run this code in a Spock Specification: Sql mockSql = Mock() However when I run the unit test, I get a nasty exception thrown…
Jason Lowenthal
  • 790
  • 1
  • 5
  • 16
6
votes
1 answer

Save or update in Groovy

Usually in Java I execute a SELECT statement and check the size of ResultSet. If it is zero I issue a INSERT and otherwise an UPDATE. Since Groovy provides syntactic sugar on top of JDBC, I'm wondering if it provides a way to ease this process? Is…
Kshitiz Sharma
  • 17,947
  • 26
  • 98
  • 169
3
votes
1 answer

What is the lifespan of a Spring Boot @RestController and an injected @Service?

I have a @RestController which has an injected @Service bean. I am having trouble understanding the lifespan of the Controller and its Service. Is it on a per-request basis? Or is it longer than that? I am new to Spring and how beans are…
David T
  • 765
  • 6
  • 18
2
votes
2 answers

Groovy , how to pass in inline variables,i.e ${variable} statement from file?

I have an interesting problem in Groovy. Hope someone can help me. Basically I am using Groovy Sql. I need to select multiple tables in different databases. My second query depends on other query's, for example: "select * from table1-in-db1 where…
Yang Lu
  • 21
  • 2
2
votes
1 answer

How do you know when GroovyStrings are not treated the same as Strings?

I've just run into a confusing issue in Groovy while trying to modify a MySQL database. What appears to be identical code throws an Exception unless my GroovyString is explicitly converted to a java.lang.String: import groovy.sql.Sql def sql =…
Armand
  • 23,463
  • 20
  • 90
  • 119
1
vote
1 answer

Using groovy: update timestamp oracle column

I have two groovy scripts that make respectively an insert and an update on a oracle table that has a string column and two timestamp columns, created like as follows: CREATE TABLE sn_token ( "token" varchar2(500 char) NOT NULL, created_at…
Luca
  • 135
  • 1
  • 2
  • 10
1
vote
2 answers

How to read each row in a groovy-sql statement?

I am trying to read a table having five rows and columns. I have used sql.eachRow function to read eachRow and assign the value to a String. I am getting an error "Groovy:[Static type checking] - No such property: MachineName for class:…
user9630935
  • 349
  • 1
  • 4
  • 18
1
vote
1 answer

Groovy concatenate to dynamic query

In a little new to Groovy and am creating a piece of code which executes an sql query using a dynamic sql string. def executeQuery(String csvQueryInList) { def result = sql.rows('SELECT * FROM mySchema.myTable WHERE id IN (?,?)', ['1', '2']) …
Richie
  • 4,989
  • 24
  • 90
  • 177
1
vote
1 answer

GroovySql: How to update a table with Arraylist variables

I am trying to write an GroovySQL script that will have three different Arraylist variable. A1[1,2,3],A2[4,5,6],A3[7,8,9]. I want to update the table such that three rows of the three columns of the table are updates as Data should be (in row…
user3384231
  • 3,641
  • 2
  • 18
  • 27
1
vote
0 answers

How to deal with an abandoned connection?

I'm running some Groovy SQL in a Grails service and often get the following error message: org.springframework.transaction.interceptor.TransactionInterceptor - Application exception overridden by commit exception java.sql.SQLException:…
zoran119
  • 10,657
  • 12
  • 46
  • 88
1
vote
0 answers

Groovy - Stored procedures that returns an OracleTypes.ARRAY

I have an issue with Groovy SQL while calling a Stored procedure which returns OracleTypes.ARRAY as output parameter. Java Code (Working fine): callableStatement.registerOutParameter(37, OracleTypes.ARRAY, DEVICE_RAW_DATA_ARRAY); OracleTypes.ARRAY…
Ram
  • 11
  • 3
1
vote
2 answers

Groovy Sql rows

Hello I am trying to get rows using Groovy Sql connection but it returns me records as a List inside a List. The following: Sql sql = new Sql(dataSource) List row = sql.rows('select * from user where username=:userName and…
Piyush Chaudhari
  • 962
  • 3
  • 19
  • 41
1
vote
1 answer

Call stored procedure in groovy and retrieve the OUT parameter and Cursor

I have a Stored Procedure that returns a VARCHAR OUT and a Cursor. The rows is always null and I need the result set in it. How do I get it? I get the OUT value in iStatus as expected. def rows = sql.call stmt, parameters, { it -> iStatus = it }
Vinodh Thiagarajan
  • 758
  • 3
  • 9
  • 19
1
vote
2 answers

Copy db table from one server to another server using groovy

is there an easy way to query data from one server (select * from table_abc) and insert the result into a different server (insert into table_abc) ? Both server are using eg. db2, oracle etc. and tables containing various datatyps (varchar, varchar…
1
vote
2 answers

Groovy Sql.execute() with sql statement as string variable not working

I am trying to execute a sql statement in groovy by passing the statement as a string variable rather than a string literal. The reason I am using a string variable is because I am reading the sql statement from a file. For example (assuming sql…
jwest
  • 100
  • 1
  • 1
  • 9
1
2