Hi,

Thanks a lot for reporting this issue! This is a pretty serious
problem... I didn't know getSchemaName is never supposed to return
null. According to the JDBC specification, the method is supposed to
return an empty string if not applicable, this is what I will do
within H2 for this case. The same for getTableName.

This will be fixed in the next release.

Regards,
Thomas

On Thu, Jul 19, 2012 at 7:35 PM, Vinod <[email protected]> wrote:
> 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.

-- 
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
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.

Reply via email to