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).
-
1What database are you using? MySQL? PostgreSQL? SQL Server? Derby? Something else?Luke Woodward– Luke Woodward2013-09-28 11:35:13 +00:00Commented Sep 28, 2013 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– Thorbjørn Ravn Andersen2013-09-28 19:34:31 +00:00Commented Sep 28, 2013 at 19:34
-
Java DB used to be called (and perhaps is still referenced as ) DerbyBrian Agnew– Brian Agnew2016-04-07 09:01:26 +00:00Commented Apr 7, 2016 at 9:01
Add a comment
|
2 Answers
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)
2 Comments
Brian Agnew
Does this work with JavaDb (aka Derby?). I don't believe it does
SpringLearner
@BrianAgnew I am not sure about Derby. This was very old question and at that time tags were java,database,netbeans and jdbc