String or binary data would be truncated on time input to database
How do I get the current time and input it into SQL server. There is my
table:
CREATE TABLE [dbo].[Audit](
[PK_Audit] [int] IDENTITY(1,1) NOT NULL,
[SequenceNumber] [int] NOT NULL,
[TableName] [varchar](50) NOT NULL,
[RunDate] [datetime] NOT NULL,
[StartTime] [datetime] NOT NULL,
[EndTime] [datetime] NOT NULL,
[Description] [varchar](max) NULL,
[Status] [varchar](50) NOT NULL,
[ProcessName] [nchar](10) NOT NULL,
[InsertCount] [int] NOT NULL,
[UpdateCount] [int] NULL,
[DeleteCount] [int] NULL,
CONSTRAINT [PK_Audit] PRIMARY KEY CLUSTERED
(
[PK_Audit] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY =
OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
I am trying to use calander to get the time and input it into the database:
Calendar cal = Calendar.getInstance();
java.util.Date start = cal.getTime();
To me it looked like you need to convert it to something SQL understands
so I did the following:
audit.setDate(4, new java.sql.Date(start.getTime()));
When I execute the query I get the following error:
com.microsoft.sqlserver.jdbc.SQLServerException: String or binary data
would be truncated.
What am I doing wrong?
No comments:
Post a Comment