aspose file tools*
The moose likes JDBC and the fly likes Adding Columns dynamically through UI Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Adding Columns dynamically through UI" Watch "Adding Columns dynamically through UI" New topic
Author

Adding Columns dynamically through UI

hariharan jayaprakash
Ranch Hand

Joined: Sep 09, 2010
Posts: 63
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: 19760
    
  20

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 - OCEEJBD 6
How To Ask Questions How To Answer Questions
hariharan jayaprakash
Ranch Hand

Joined: Sep 09, 2010
Posts: 63
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: 2510
    
  10

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 and ITIL foundation
youtube channel
hariharan jayaprakash
Ranch Hand

Joined: Sep 09, 2010
Posts: 63
oh okay thanks .. i ll start tryin to implement..
 
 
subject: Adding Columns dynamically through UI