• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Adding Columns dynamically through UI

 
hariharan jayaprakash
Ranch Hand
Posts: 67
  • 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..
 
Rob Spoor
Sheriff
Pie
Posts: 20546
57
Chrome Eclipse IDE Java 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: 67
  • 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?
 
Jan Cumps
Bartender
Posts: 2588
11
C++ Linux Netbeans IDE
  • 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: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oh okay thanks .. i ll start tryin to implement..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic