I'm trying to alter the size of a field in my Java DB Database. I just can't seem to do it. My current data type is varchar(50)
and I want to update it to varchar(150)
.
Asked
Active
Viewed 9,943 times
3

Brian Agnew
- 268,207
- 37
- 334
- 440

Josh Pritchard
- 141
- 1
- 7
-
1What database are you using? MySQL? PostgreSQL? SQL Server? Derby? Something else? – Luke Woodward Sep 28 '13 at 11:35
-
JDBC is just a tunnel between your code and the database so you need your SQL to be valid for the particular database you are using. – Thorbjørn Ravn Andersen Sep 28 '13 at 19:34
-
Java DB used to be called (and perhaps is still referenced as ) Derby – Brian Agnew Apr 07 '16 at 09:01
2 Answers
8
Solved:
ALTER TABLE [table] ALTER COLUMN [column] SET DATA TYPE [type];
I wasn't using the SET DATA TYPE
function and was instead just trying to redeclare it by using ALTER COLUMN [column] [type];

Brian Agnew
- 268,207
- 37
- 334
- 440

Josh Pritchard
- 141
- 1
- 7
1
For mysql you can do this way
alter table table_name modify col_name varchar(150)
JDBC codes
PreparedStatement pt =connection.prepareStatement("alter table table_name modify col_name varchar(150)");
pt.executeUpdate();
In ms sql server use this command
ALTER TABLE [table_name]
ALTER COLUMN [Column_name] varchar(150)

SpringLearner
- 13,738
- 20
- 78
- 116
-
-
@BrianAgnew I am not sure about Derby. This was very old question and at that time tags were java,database,netbeans and jdbc – SpringLearner Apr 07 '16 at 09:06