Schema Name is empty - converting resultset into cachedRowSet

381 views
Skip to first unread message

Vinod

unread,
Jul 19, 2012, 1:35:57 PM7/19/12
to h2-da...@googlegroups.com
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
H2SchemaNameEmpty.java

Thomas Mueller

unread,
Jul 22, 2012, 2:23:37 PM7/22/12
to h2-da...@googlegroups.com
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
> --
> 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 h2-da...@googlegroups.com.
> To unsubscribe from this group, send email to
> h2-database...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/h2-database?hl=en.

Vinod

unread,
Jul 23, 2012, 10:11:24 AM7/23/12
to h2-da...@googlegroups.com
This particular query is executed against dual. Shall it not return PUBLIC instead of empty schema name?
> h2-database+unsubscribe@googlegroups.com.

Thomas Mueller

unread,
Jul 24, 2012, 1:58:56 PM7/24/12
to h2-da...@googlegroups.com
Hi,

As far as I understand, the method is supposed to return the schema
name of the column. Since '1' is a constant and not a column, the
schema name (and table name) is empty. I have tested this with other
databases (PostgreSQL, HSQLDB, and Derby I think) and they work in the
same way.

Regards,
Thomas
>> > h2-database...@googlegroups.com.
>> > 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 view this discussion on the web visit
> https://groups.google.com/d/msg/h2-database/-/zbPkSTVhvjcJ.
>
> To post to this group, send email to h2-da...@googlegroups.com.
> To unsubscribe from this group, send email to
> h2-database...@googlegroups.com.

priyanka priya

unread,
Jul 25, 2012, 12:54:59 AM7/25/12
to h2-da...@googlegroups.com
hello sir..

I want to no in h2 how we backup database...for each table..

I want the method to backup each table..

if anyone has answer...please reply....

Thomas Mueller

unread,
Jul 25, 2012, 1:09:15 AM7/25/12
to h2-da...@googlegroups.com
Hi,

> I want to no in h2 how we backup database...for each table..
> I want the method to backup each table..
> if anyone has answer...please reply....

I'm sorry, but nobody should reply to your mail, because you have so
called "hijacked" an email thread. The subject of this email thread is
"Schema Name is empty - converting resultset into cachedRowSet", so
this email thread is about the problem that the schema name is empty.
You, on the other hand, have replied to this email, using the same
subject, but asking a different question that has nothing to do (as
far as I'm aware) of the problem with empty schema name in the result
set meta data. Your question is about backup. So I'm afraid it is bad
if somebody would reply to your mail, because that way other people
might be tempted to so called "hijack" other email threads, and this
would lead to other people not able to find answers for questions that
have been asked before.

To get a reply, I suggest you send a different mail with an
appropriate subject. Or you ask your question at the StackOverflow.com
website.

Kind regards,
Thomas
Reply all
Reply to author
Forward
0 new messages