Sunday, September 12, 2010

Groovy, Blob to String

sql.eachRow "select * from table1",
{
///println it.id

String result = ""
blobTest = (oracle.sql.BLOB)it.mydoc

byte_stream_test = blobTest.getBinaryStream()
byte_stream_test.eachLine {charset->

result += charset+"\n" }
println result;


}

Saturday, September 11, 2010

Staring Oracle in Ubuntu. - Problem and work around resolution.

1) /etc/init.d/./oralcle-xe.sh start


2) error:
Copyright (c) 1991, 2005, Oracle. All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC_FOR_XE)))
TNS-12541: TNS:no listener
TNS-12560: TNS:protocol adapter error
TNS-00511: No listener
Linux Error: 111: Connection refused
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=lexi)(PORT=1521)))
TNS-12541: TNS:no listener
TNS-12560: TNS:protocol adapter error
TNS-00511: No listener
Linux Error: 111: Connection refused
byorn@lexi:/etc/init.d$ sudo ./oracle-xe restart
Shutting down Oracle Database 10g Express Edition Instance.
Stopping Oracle Net Listener

3) Now:
sudo /etc/init.d/./oralcle-xe.sh restart

4) success:
ler(s) for this service...
The command completed successfully


Any body have any idea about this?

Friday, September 10, 2010

DB Connectivity With Groovy

import java.sql.Connection
import java.sql.DriverManager
import javax.sql.DataSource
import groovy.sql.Sql
import oracle.jdbc.driver.OracleTypes

driver = oracle.jdbc.driver.OracleDriver
Connection conn = DriverManager.getConnection(
'jdbc:oracle:thin:rcms/password@localhost:1521:xe');

/*
*
* Here we call a procedural block with a closure.
* ${Sql.INTEGER} and ${Sql.VARCHAR} are out parameters
* which are passed to the closure.
*
*/
Sql sql = new Sql(conn);

//define a closure
myclosure = {println it.cusid + " " + it.cusname }

sql.eachRow("select * from tbl_customer", myclosure);