Ask a Question

groovy blob read

SOLVED
Gepir
Occasional Contributor

groovy blob read

Hi,

 

I;m trying to read blob from DB, I've created this script (below) 

 

def blob = sql.firstRow("SELECT CASE.APPLICATIONS.DATAPACKAGE as blob FROM CASE.APPLICATIONS WHERE APPLICATIONS.STATUS = '0' And APPLICATIONS.APPLICATIONNAME Is Not Null ORDER BY APPLICATIONS.CREATED DESC").blob
String datapackage = new String(blob.getBytes(1,(int)blob.length()))
log.info datapackage
byte[] readBits = datapackage.getBytes(1L, datapackage.length()as int)
log.info 'bits: ' + new String(readBits)
sql.close()

 

 

but I'm still getting this error, line 8 is:

byte[] readBits

groovy.lang.MissingMethodException: No signature of method: java.lang.String.getBytes() is applicable for argument types: (java.lang.Long, java.lang.Integer) values: [1, 184] Possible solutions: getBytes(), getBytes(java.lang.String), getBytes(java.nio.charset.Charset), getBytes(int, int, [B, int), getClass(), getChars() error at line: 8

 

Thanks for help

2 REPLIES 2
Gepir
Occasional Contributor

So I've found the solution...

import groovy.sql.Sql
import java.sql.*

sql = Sql.newInstance("jdbc:oracle:thin:@::", "", "")
//selct blob
java.sql.Blob blob = sql.firstRow("SELECT CASE.APPLICATIONS.DATAPACKAGE as blob FROM CASE.APPLICATIONS WHERE APPLICATIONS.STATUS = '0' And APPLICATIONS.APPLICATIONNAME Is Not Null ORDER BY APPLICATIONS.CREATED DESC").blob
byte[] bdata = blob.getBytes(1, (int) blob.length());
String text = new String(bdata);
log.info text;

next step is decrypt blob... 

Hi,

 

I am going to use your script for reading BLOB from oracle db.

In the below line after jdbc connection is it username and password field?

sql = Sql.newInstance("jdbc:oracle:thin:@::", "", "")

I will write you if I need any help.

Thanks in advance.

 

cancel
Showing results for 
Search instead for 
Did you mean: