You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Vit Novak (JIRA)" <ji...@apache.org> on 2016/01/12 14:31:39 UTC

[jira] [Commented] (GROOVY-7105) Oracle Thin Driver Fails with an Exception in Groovy 2.3.x

    [ https://issues.apache.org/jira/browse/GROOVY-7105?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15093870#comment-15093870 ] 

Vit Novak commented on GROOVY-7105:
-----------------------------------

I don't think that this should by closed as a *Not A Problem* at all. We encountered simillar issue with a code (parsing excel with poi) that worked in older versions:
{code}
@Grab('org.apache.poi:poi:3.11')
@Grab('org.apache.poi:poi-ooxml:3.11')

stream = new FileInputStream(new File('Any non empty xlsx file path'))
workbook = new org.apache.poi.xssf.usermodel.XSSFWorkbook(stream)
sheet = workbook.getSheetAt(0)
rowIterator = sheet.rowIterator()
println rowIterator.next().getCell(0).toString()
{code}

This results in {{NoClassDefFoundError: org/openxmlformats/schemas/spreadsheetml/x2006/main/CTExtensionList}}, please note this is just an example and we cannot simply add another {{@Grab}}.

*Problem is*, that there are lots of groovy scripts out there between customers, and with a new version of groovy lots of them will stop working. *Modyfing the classpath* is not always simple and it *should not be necessary*, since the extra dependencies are not used and even the *java version* works without them:
{code}
InputStream stream = new FileInputStream(new File("Any non empty xlsx file path"));
XSSFWorkbook workbook = new org.apache.poi.xssf.usermodel.XSSFWorkbook(stream);
XSSFSheet sheet = workbook.getSheetAt(0);
Iterator<Row> rowIterator = sheet.rowIterator();
rowIterator = sheet.rowIterator();
System.out.println(rowIterator.next().getCell(0).toString());
{code}

Another workaround, {{@CompileStatic}} means modifying lots of old scripts, maybe loosing some functionality and complicating scripts due to some obscure classpath issues. Simply Groovy becoming not so much groovy anymore.

Above all, both _solutions_ are just workarounds, there should be *real fix* to this, so why was this issue closed?

> Oracle Thin Driver Fails with an Exception in Groovy 2.3.x
> ----------------------------------------------------------
>
>                 Key: GROOVY-7105
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7105
>             Project: Groovy
>          Issue Type: Bug
>          Components: groovy-jdk, SQL processing
>    Affects Versions: 2.3.0
>            Reporter: Charlie Hubbard
>            Priority: Blocker
>
> Trying to load the Oracle driver in Groovy fails with the following error:
> java.lang.NoClassDefFoundError: oracle/xdb/XMLType
> 	at java_sql_Connection$getMetaData.call(Unknown Source)
> 	at db_test.printMetaData(db_test.groovy:9)
> 	at db_test.printMetaData(db_test.groovy)
> 	at db_test$printMetaData$0.callCurrent(Unknown Source)
> 	at db_test.run(db_test.groovy:45)
> Caused by: java.lang.ClassNotFoundException: oracle.xdb.XMLType
> 	... 5 more
> This works in Groovy 2.1.x.  This is loading the thin driver which doesn't require extra libraries.  It appears that Groovy loads Oracle's OCI driver which requires these additional jar files and fails.
> {code}
> import groovy.sql.Sql
> import java.sql.ResultSet
> import java.sql.DatabaseMetaData
> void printMetaData( Sql sql, catalog = null, schema = null ) {
>     try {
>         DatabaseMetaData metadata = sql.connection.getMetaData()
>         
>         ResultSet rs = metadata.getCatalogs()
>         while( rs.next() ) {
>            String catalogName = rs.getString("TABLE_CAT")
>            println("${catalogName}")
>         }
>         rs.close()
>         
>         rs = metadata.getSchemas()
>         while( rs.next() ) {
>            String catalogName = rs.getString("TABLE_CAT")
>            String schemaName = rs.getString("TABLE_SCHEM")
>            
>            println("${catalogName}.${schemaName}")
>         }
>         rs.close()
>         
>         def types = [ "TABLE" ]
>         rs = metadata.getTables( catalog, schema, null, types.toArray( new String[types.size()]) )
>         while( rs.next() ) {
>            String catalogName = rs.getString("TABLE_CAT")
>            String schemaName = rs.getString("TABLE_SCHEM")
>            String tableName = rs.getString("TABLE_NAME")
>            println("${catalogName}.${schemaName}.${tableName}")
>         }
>         rs.close()
>     } finally {
>         sql.close()
>     }
> }
> oracle = Sql.newInstance("jdbc:oracle:thin:@//localhost:1521/PDB1", "someUser", "somePassword", "oracle.jdbc.driver.OracleDriver")
> printMetaData( oracle )
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)