I have a List<String> tableNames;
I wanted to
In particular IBM DB2 UDB has some isssue where you can't retrive the metadata if table doesn't have any rows. For now we are using something like
for(String tableName :tableNames)
//Here I wanted to get table meata data (ie, column names and types)
If result set is null we are inserting dummy data and retrieving metadata using simple jdbc like below:
select * from table_name fetch first 1 row only
Is there anyway I can use jdbcTemplate to avoid all above bolierplate code?
ResultSet rs = stmt1.executeQuery("select * from "+tableName+" fetch first 1 rows only with ur") ;
if(rs == null)
//build a statment like
insert into schema_a.Tablename select * from schema_b.TableName
I dont want to insert any dummy data.
Here in my case jdbcTemplate is built in runtime based on what environment user selected and we are using weblogic data sources, SchemaawareProxy to set schema.
I can write something like
But here I have a risk always "what if other schema doesn't have data?"
MyCustomObj obj= jdbcTemplate.queryForObject(sql, new MyRowMapperImpl())
if(obj == null)
jdbcTemplate.update(insert into schema_a.Tablename select * from schema_b.TableName fetch first 1 row only");
//Then again get resultset or directly get metadata from other schema.
I have read this thread
But In my case I am dealing with DB2 UDB 9.5.