Below is the table creation script
CREATE TABLE [dbo].[Employee](
[empId] [int] IDENTITY(9,1) NOT NULL,
[empName] VARCHAR(255) NOT NULL,
[empOrgId] [int] NOT NULL,
)
ALTER TABLE [dbo].[Employee] ADD CONSTRAINT [DF__Employee__empOrgId] DEFAULT ((13)) FOR [empOrgId]
GO
when i am trying to insert to tables with simplejdbcinsert
SimpleJdbcInsert simpleJdbcInsert = new SimpleJdbcInsert(jdbcTemplate);
simpleJdbcInsert .withTableName("Employee")
.usingGeneratedKeyColumns("empId");
SqlParameterSource params = new MapSqlParameterSource()
.addValue("empName","john")
Number number = simpleJdbcInsert.executeAndReturnKey(params);
System.out.println("number"+number);
Note:I want empOrgId defaulted to 13 whenever value is not passed but getting below
Error message:
com.microsoft.sqlserver.jdbc.SQLServerException: Cannot insert the value NULL into column 'empOrgId', table 'Employee'; column does not allow nulls. INSERT fails