Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Adding Columns dynamically through UI

 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to add columns dynamically through UI?..

I am just doing simple exercises on Servlets and JSP's.

I have a doubt:

Created One table called "Product" and added few columns like "ID, Name etc"..

Now i want to add new columns through UI Itself, can we achieve tat?..

For ex: create a page called "Add column" , In that we have to provide

Column Name(Price) and Data type(Integer) for the new column
.. once click on create button, It should create a new column in our existing table..
 
Sheriff
Posts: 21972
106
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You'll need to execute an "ALTER TABLE" query. The exact syntax depends on the database server used, but in general it's something like this:
That last NULL indicates the column can have NULL values. Use "NOT NULL" instead to indicate it cannot have NULL values, but that's only possible if you have no rows yet, unless you specify a default value:
Final part of the lesson: you can also change existing columns, to change the type, allow/disallow NULL values or change the default:
 
hariharan jayaprakash
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to achieve this through User Interface Itself..

not like through query.. i want to do some logic in JDBC Code to add column dynamically..

Like I created one JSP

Column Name: ***
Data Type : ***

and add one button, when we click on tat button, i should add new column dynamically..

am i clear?
 
Bartender
Posts: 2658
19
Netbeans IDE C++ Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. That is what Rob is suggesting.
The UI can grab what the user enters. Then, your code uses JDBC to send an ALTER TABLE... statement to your database.
 
hariharan jayaprakash
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oh okay thanks .. i ll start tryin to implement..
 
Screaming fools! It's nothing more than a tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic