I am connecting my dropwizard application with the Postgres db. I am creating tables dynamically at the time of starting the application server.
private static void createTableUser(Connection connection) throws SQLException {
Statement statement= connection.createStatement();
statement.executeUpdate("CREATE TABLE USERR"
+"("+
"id INTEGER,"+
"first_name VARCHAR(20),"+
"middle_name VARCHAR(20),"+
"last_name VARCHAR(20),"+
"age INTEGER,"+
"image_url VARCHAR(250),"+
"joining_date DATE ,"+
"country_code INTEGER,"+
"mobile_no VARCHAR(20),"+
"email_id VARCHAR(20),"+
"CONSTRAINT pk_user PRIMARY KEY (id)"+
")"
);
statement.close();
}
Above is the function creating my table. This way it is working very well. But I want to make id
as auto increment. I went through articles which gave suggestion of keyword "SERIAL", "BIGSERIAL", "SMALLSERIAL"
.
When I was using sql server I was doing it the way
id INTEGER IDENTITY (1)
and here also IDENTITY
is available as option but when I tried it I was getting error
Exception in thread "main" org.postgresql.util.PSQLException: ERROR: syntax error at or near "IDENTITY"
Can anyone help me? Thanks in advance