I am building a reporting tool and I need to execute queries on remote databases and store the result set in my own database (because I do not have write permission on remot
Maybe this is a little tricky, but I think it might help you.
JDBC ResultSet objects have a getMetaData() method that returns a ResultSetMetaData object that contains, among other things, the column names and column types. You could do something like this:
ResultSet rs;
String strSQL;
...
strSQL = "create table tbl ("
for(i=0;i0)
strSQL += ", "
strSQL += rs.getMetaData().getColumnName(i)
+ " "
+ rs.getMetaData().getColumnType(i);
}
strSQL+= ")"
....
You can construct this way a valid SQL DML that has the columns you need. After that, all that remains is populate the table.
Hope this helps you.