Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes JDBC and the fly likes howto modify database structure ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "howto modify database structure ?" Watch "howto modify database structure ?" New topic
Author

howto modify database structure ?

Alvin chew
Ranch Hand

Joined: Jan 08, 2004
Posts: 834
hi, does anyone have idea to modify structure od existing database, say example, i have a table in mysql, and this table contains 5 fields/columns now, we now allow user to add existing fields/columns in the existing table, can we do that ? thank you !
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
i think you mean allow user to add new fields/columns in existing table. yeah we can.
[ September 28, 2004: Message edited by: adeel ansari ]
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
make two tables for example,

USER_DEFINED_COLUMN
COLUMN_ID, TABLE_ID, STATUS_ID, COLUMN_NAME, COLUMN_LENGTH, LABLE, DATATYPE

DYNAMIC_TABLE
TABLE_ID, TABLE_NAME

now you can manipulate the new fields with the help of these tables. you can:

delete added columns
modify added columns
add new columns

these table just keep the record of the added columns. the real columns are gonna add in the real table.

if you need some code i think i can provide you some.
Alvin chew
Ranch Hand

Joined: Jan 08, 2004
Posts: 834
adeel, kindly please provide me some sample code on it if possible , thank you very much for your help !!

i'm sorry since i'm not clear on your idea, do you mind to specify it ? thank you again !!
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Ok this is my DAO. I hope you would be able to get logic atleast.

method for adding fields in the existing table



method for deleting fields (previously added) in the existing table



method for modifying fields (previously added) in the existing table


[ September 28, 2004: Message edited by: adeel ansari ]
Alvin chew
Ranch Hand

Joined: Jan 08, 2004
Posts: 834
adeel, thanks for helping !!!
Alvin chew
Ranch Hand

Joined: Jan 08, 2004
Posts: 834
adeel, any reason why you put "?" in your query string ?
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
we should use ? when using prepared statement. afterwards by doing

pStmt.setString(1, "example");

the first ? of your string gets changed by the value. in this case ? would be changed into "example".

- it will allow you to set the value on the fly
- it will save you from sql injection
- easy in writing. dont really have to bother with string concatenations
- prepared statements are precompiled unlike statement
Alvin chew
Ranch Hand

Joined: Jan 08, 2004
Posts: 834
thanks for answering , adeel !!
 
Don't get me started about those stupid light bulbs.
 
subject: howto modify database structure ?