I have a ResultSetMetaData
object.
PreparedStatement ps=con.prepareStatement("select var1, var2 from test1, test2");
ResultSet rs=ps.executeQuery();
ResultSetMetaData rsmd=rs.getMetaData();
System.out.println("Total columns: "+rsmd.getColumnCount());
System.out.println("Column Name of 1st column: "+rsmd.getColumnName(1));
System.out.println("Column Type Name of 1st column: "+rsmd.getColumnTypeName(1));
I need to create an new empty table with all the fields in the above ResultSetMetaData
- Open a new connection in different database
- Use the meta data above
- Create a new empty table with this meta data
I can see two possible solutions
- Reflection. In general to create a table with Hibernate, I need to create a
bean
. But I don't know in advance what fields theResultSetMetaData
will contain . Should I create thisbean
with reflection? - HQL CREATE TABLE . Is this possible?
What is the simplest way to do this? How can I do this?