• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • Carey Brown
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • fred rosenberger
  • salvin francis

How to create and retrieve tables dynamically using JDBC?

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How to create a dynamic Table using JDBC ?
I was working on creating, JDBC code that can create Tables on the bases of user's input and can also show the tables present in the database


For now I am using Switch case to take users input how many columns user wants to enter. and setting every column as varchar. But this is not the optimal solution of this problem what if user wants to insert 10 columns or more we can't handle it manually by switch or else if is there any way to make it dynamic.
similar issue is there with selection, while fetching and displaying a table, we need to write resultSet.getInt() or getBoolean or getString, and here we should know all the columns also. But how to fetch all tables dynamically ?

Anyone can please help me with this?
 
Saloon Keeper
Posts: 23882
162
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First, let me warn that creating arbitrary tables/columns in a database isn't a practice I'd recommend. You can end up with a big mess of stuff that nobody understands and nobody can maintain. Fixed schemas are generally a better way to go.

But there are several ways to determine what's defined in a schema. If you have a ResultSet, you can get the metadata of the ResultSet, for example.

All modern databases have an information schema that's a database that describes all the databases in the server instance. This provides standardized tables that you can do SQL queries against to get schema information.
 
reply
    Bookmark Topic Watch Topic
  • New Topic