| Author |
Alter Query giving an error
|
Betsy Camel
Ranch Hand
Joined: Oct 02, 2003
Posts: 119
|
|
public static String alterQuery(String ColumnName) throws SQLException { String msg = "Added a Column Successfully"; stmt.executeUpdate("alter table Machine_Details add '"+ColumnName+"' varchar(10)"); return msg; } this is being accessed in my jsp like String message = myclass.alterQuery(request.getParameter("namecolumn")); where namecolumn is the textbox name. this is giving an error .. java.sql.SQLException: [Microsoft][ODBC SQL Server Driver][SQL Server]Line 1: Incorrect syntax near 'Machine_length'. here machine _length is the value given in the text box... plz help
|
 |
Dave Salter
Ranch Hand
Joined: Jul 20, 2005
Posts: 292
|
|
|
Do you know the actual SQL that is being issued?
|
 |
Paul Sturrock
Bartender
Joined: Apr 14, 2004
Posts: 10336
|
|
Double check the alter table syntax for SQL Server (here). You don't put quotes round new columns. As an aside, I'm guessing you have your reasons, but its not usually a good idea to allow DDL statements from a Web App. [ September 22, 2005: Message edited by: Paul Sturrock ]
|
JavaRanch FAQ HowToAskQuestionsOnJavaRanch
|
 |
Maximilian Xavier Stocker
Ranch Hand
Joined: Sep 20, 2005
Posts: 381
|
|
I believe the syntax should be ALTER TABLE tablename ADD COLUMN columnname datatype Because you could be adding an index too. I am not sure about the quotes around the name either but at least try specifiying that you are in fact adding a COLUMN.
|
 |
 |
|
|
subject: Alter Query giving an error
|
|
|