| Author |
Adding Columns dynamically through UI
|
hariharan jayaprakash
Ranch Hand
Joined: Sep 09, 2010
Posts: 60
|
|
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
Joined: Oct 27, 2005
Posts: 19232
|
|
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:
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
hariharan jayaprakash
Ranch Hand
Joined: Sep 09, 2010
Posts: 60
|
|
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
Joined: Dec 20, 2006
Posts: 2350
|
|
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.
|
OCUP UML fundamental
ITIL foundation
|
 |
hariharan jayaprakash
Ranch Hand
Joined: Sep 09, 2010
Posts: 60
|
|
oh okay thanks .. i ll start tryin to implement..
|
 |
 |
|
|
subject: Adding Columns dynamically through UI
|
|
|