3

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).

3
  • 1
    What database are you using? MySQL? PostgreSQL? SQL Server? Derby? Something else? Commented 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. Commented Sep 28, 2013 at 19:34
  • Java DB used to be called (and perhaps is still referenced as ) Derby Commented Apr 7, 2016 at 9:01

2 Answers 2

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];

Sign up to request clarification or add additional context in comments.

Comments

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)

2 Comments

Does this work with JavaDb (aka Derby?). I don't believe it does
@BrianAgnew I am not sure about Derby. This was very old question and at that time tags were java,database,netbeans and jdbc

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.