Hi,

I am converting resultset to a CachedRowSet, which expects a schema 
name(which is empty).
*
*
*Code: *(Full code is attached)
-------------------------------------------- 
        Connection conn = DriverManager.getConnection("jdbc:h2:mem:TempDB");
        String queryStr = "select '1' from dual";
        PreparedStatement stmt = conn.prepareStatement(queryStr);
        ResultSet rs = stmt.executeQuery();
        
        // following shows that schema name is null
        ResultSetMetaData metaData = rs.getMetaData();
        String schemaName = metaData.getSchemaName(1);
        System.out.println("schemaName=" + schemaName);
        
        // this is the actual call I am making causing NullPointerException
        CachedRowSet sunCachedRowSet = new CachedRowSet();
        sunCachedRowSet.populate(rs);
--------------------------------------------

*Output:*
-------------------------------------------- 
schemaName=null
Exception in thread "main" java.lang.NullPointerException
at java.lang.String.<init>(Unknown Source)
at 
sun.jdbc.rowset.RowSetMetaDataImpl.setSchemaName(RowSetMetaDataImpl.java:269)
at sun.jdbc.rowset.CachedRowSet.initMetaData(CachedRowSet.java:680)
at sun.jdbc.rowset.CachedRowSet.populate(CachedRowSet.java:647)
at com.H2SchemaNameEmpty.main(H2SchemaNameEmpty.java:28)
-------------------------------------------- 

I even tried by setting the schema to public: 
[jdbc:h2:mem:TempDB;SCHEMA=PUBLIC].

To make it work, I modified JdbcResultSetMetaData.getSchemaName to return 
"PUBLIC" when it is null.
Is there a better way to resolve this.

Thanks,
Vinod

-- 
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/h2-database/-/ctRP4sRSC6AJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/h2-database?hl=en.

package com;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;

import sun.jdbc.rowset.CachedRowSet;

public class H2SchemaNameEmpty {
    public static void main(String[] args) throws Exception {
        Class.forName("org.h2.Driver");
        
//        Connection conn = DriverManager.getConnection("jdbc:h2:mem:TempDB;SCHEMA=PUBLIC");
        Connection conn = DriverManager.getConnection("jdbc:h2:mem:TempDB");
        String queryStr = "select '1' from dual";
        PreparedStatement stmt = conn.prepareStatement(queryStr);
        ResultSet rs = stmt.executeQuery();
        
        // following shows that schema name is null
        ResultSetMetaData metaData = rs.getMetaData();
        String schemaName = metaData.getSchemaName(1);
        System.out.println("schemaName=" + schemaName);
        
        // this is the actual call I am making causing NullPointerException
        CachedRowSet sunCachedRowSet = new CachedRowSet();
        sunCachedRowSet.populate(rs);
    }
}

Reply via email to