mysql - Java DatabaseMetaData.getSchemas() returns empty ResultSet, expected non-empty ResultSet -


trying understand going on here. databasemetadata returning empty result set, sql query same not. not major issue using second code example work around.

databasemetadata dmd = this.connection.getmetadata(); resultset rs = dmd.getschemas(); while (rs.next()){   // empty result set } 

expected non-empty result set.

resultset rs = this.connection.preparestatement("select schema_name information_schema.schemata;").executequery(); while (rs.next()){   // non-empty result set expected results } 

expected non-empty result set , got it.

as far can tell mysql jdbc driver considers catalog, not schema. should use getcatalogs instead (and everywhere use it, need use catalog parameter, not schema parameter).

the getschemas method in connector/j returns empty result set:

public java.sql.resultset getschemas() throws sqlexception {     field[] fields = new field[2];     fields[0] = new field("", "table_schem", java.sql.types.char, 0);     fields[1] = new field("", "table_catalog", java.sql.types.char, 0);      arraylist<resultsetrow> tuples = new arraylist<resultsetrow>();     java.sql.resultset results = buildresultset(fields, tuples);      return results; } 

the getcatalogs returns result of show databases. , in databasemetadatausinginfoschema see table_schema column of information schema aliased table_cat (for catalog) , catalog parameter being passed value table_schema column in query:

string sql = "select table_schema table_cat, null table_schem, table_name,"         + "column_name, null grantor, grantee, privilege_type privilege, is_grantable information_schema.column_privileges "         + "table_schema ? , table_name =? , column_name ? order column_name, privilege_type";  java.sql.preparedstatement pstmt = null;  try {     pstmt = preparemetadatasafestatement(sql);      if (catalog != null) {         pstmt.setstring(1, catalog);     } else {         pstmt.setstring(1, "%");     }      pstmt.setstring(2, table);     pstmt.setstring(3, columnnamepattern); 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -