Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8175909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:56:39+00:00 2026-06-06T22:56:39+00:00

I am building a reporting tool and I need to execute queries on remote

  • 0

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 remote databases and also I need to cache the results to prevent further executions). Moreover, I need this capability, so I can join two result sets together and generate results based on generated results.

Now, my problem is that I do not know how to CREATE TABLE based on jdbc ResultSet. Is there any open source tools or scripts that handles this?

My application is based on Spring 3.1.0 and uses JDBC to query local and remote databases. My local database that I want to store the results is MySQL 5.5.20. (Is this a good idea to store in MySQL? Does it provide the sufficient performance?)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T22:56:40+00:00Added an answer on June 6, 2026 at 10:56 pm

    We can extract the nearest matching structure from the resultset and construct a table.
    But this can’t be the exact replica, in terms of table name, keys, engine type, whether a field is nullable or not, etc..

    Following code snippet helps you proceed in a way to get an appropriate result.

    String sql = "select * from visitors";
    ResultSet rs = stmt.executeQuery( sql );
    ResultSetMetaData rsmd = rs.getMetaData();
    int columnCount = rsmd.getColumnCount();
    String tableName = null;
    StringBuilder sb = new StringBuilder( 1024 );
    if ( columnCount > 0 ) { 
        sb.append( "Create table " ).append( rsmd.getTableName( 1 ) ).append( " ( " );
    }
    for ( int i = 1; i <= columnCount; i ++ ) {
        if ( i > 1 ) sb.append( ", " );
        String columnName = rsmd.getColumnLabel( i );
        String columnType = rsmd.getColumnTypeName( i );
    
        sb.append( columnName ).append( " " ).append( columnType );
    
        int precision = rsmd.getPrecision( i );
        if ( precision != 0 ) {
            sb.append( "( " ).append( precision ).append( " )" );
        }
    } // for columns
    sb.append( " ) " );
    
    System.out.println( sb.toString() );
    

    Executing with above part of the code, printed following string:

    Create table visitors ( ip VARCHAR( 6 ), bro VARCHAR( 6 ) )
    

    Let me hope this helps you proceed further.

    Similar example can be found at: Create a table using ResultSet ???

    UPDATE 1:

    how can I deal with types that only exist in one database and does not exist in another

    You can’t do anything when depending only on a resultset at client side application.
    It should always be the main select query that selects proper data from a composite data type like geometry, address, etc.
    Examle: select addess.city, address.zipcode, x( geometry_column ), y( geometry_column )

    To give an example of geometry data type:
    MySQL has definitions for its Spatial Support. But I am not sure how far they are good compared to SQL Server’s implementation of Spatial Data.

    geometry is a composite data type and hence can’t be retrieved by direct query.
    You require dependent function(s) that parses data from such data columns and return in readable, identifiable data formats.
    Example: create table geom ( g geometry );
    Converting ResultSet from select g from geom using JAVA to a create table statement would result with an unknwon data type for column g.

    Create table geom ( g UNKNOWN )
    

    Using x(g), y(g) co-ordinate functions on column g will return proper and acceptable data types.
    Query select x(g), y(g) from geom will be converted to

    Create table  ( x(g) DOUBLE( 23, 31 ), y(g) DOUBLE( 23, 31 ) ) 
    

    UPDATE 2:
    A resultset might be generated in combination of multiple tables using relations. There is also a chance that the resultset fields are composed of expressions and their aliases. Hence, data types of the resulting column fields or aliases are decided dynamic. Metadata is not aware of exact names of tables, column names and their original/parent data types from the query.

    So, it is not possible to get

    1. the single name of a table and use it.
    2. the parent column’s data type and use it.

    Note: This is also applicable to all other cross database specific data types, like NVARCHAR, etc..
    But, please refer to this posting for an alternative to NVARCHAR usage in MySQL.

    Before trying such dynamic data migration, it should be client applications responsibility to know the equivalent data types and use them accordingly.

    Also, refer to Data types and ranges for Microsoft Access, MySQL and SQL Server for more information.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building a reporting tool where the user can filter results by selecting one
I'm building a cross-database view that consolidates data from two different subsystems for reporting.
I'm building up a new database in SQL Server 2008 for some reporting, and
I am building out some reporting stuff for our website (a decent sized site
building a site using PHP and MySQL that needs to store a lot of
Building a Django app on a VPS. I am not very experienced with setting
We're building an application that has a database (yeah, pretty exciting huh :). The
I am building a set of class libraries that produce office open xml based
I'm building UI logging into a long-existing ASP.NET enterprise application. I have my own
I am building a report in Reporting Services 2005, where the data is retrieved

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.