org.h2.jdbc.JdbcSQLException: Hexadecimal string contains non-hex character: - database

When I am trying to insert data to H2 table, it is showing the below exception.
INSERT INTO DATA (IP,HEADERS,METHOD,BODY,ID,TIME) VALUES (?,?,?,?,?,?) -- (?1, ?2, ?3, ?4, ?5, ?6) [90004-175]
Caused by: org.h2.jdbc.JdbcSQLException: Hexadecimal string contains non-hex character: "[accept=application/json, activityid=caf59f7d-b2f1-4250-9e7a-61606ff5dace, Authorization=Bearer dc98a786-6dda-35e0-9086-7a3beba5edd5, Content-Length=19, Content-Type=application/json, Host=190.0.0.101:8248, User-Agent=curl/7.58.0]"; SQL statement:
INSERT INTO DATA (IP,HEADERS,METHOD,BODY,ID,TIME) VALUES (?,?,?,?,?,?) -- (?1, ?2, ?3, ?4, ?5, ?6) [90004-175]
Table :
CREATE TABLE IF NOT EXISTS DATA (
TIME BIGINT,
ID VARCHAR(255),
METHOD VARCHAR(255),
HEADERS BLOB,
BODY BLOB,
IP VARCHAR(255),
PRIMARY KEY(ID)
);
What can be the reason for this? How can I resolve it? Is this a problem of that type or value of inserting.
Appreciate your valuable input here.

Related

Snowflake DDL not allowing to load data into table

Not able to insert data into Snowflake table with Specific data types
This may be very silly question but i just started trying out Snowflake and stuck at first step itself .
I need to look up XML element from the DETAILS column
select testId from app_event table ;
This is how i am trying to create a table in Snowflake
create or replace table app_event (
ID varchar(36) not null primary key,
VERSION number,
ACT_TYPE varchar(255),
EVE_TYPE varchar(255),
CLI_ID varchar(36),
DETAILS variant,
OBJ_TYPE varchar(255),
DATE_TIME timestamp,
AAPP_EVENT_TO_UTC_DT timestamp,
GRO_ID varchar(36),
OBJECT_NAME varchar(255),
OBJ_ID varchar(255),
USER_NAME varchar(255),
USER_ID varchar(255),
EVENT_ID varchar(255),
FINDINGS varchar(255),
SUMMARY variant
);
This is my Sample data
ID VERSION ACT_TYPE EVE_TYPE CLI_ID DETAILS OBJ_TYPE DATE_TIME AAPP_EVENT_TO_UTC_DT GRO_ID OBJECT_NAME OBJ_ID USER_NAME USER_ID EVENT_ID FINDINGS SUMMARY
003cce70-ffff-43bc-8905-5e1d64475aa1 0 SCREENED_CASE WORLDCHECK 0 <?xml version="1.0" encoding="UTF-8" standalone="yes"?><testPayload><testId>565656-21cf-4c7e-8071-574a1ef78981</testId><testCode>COMPLETED</testCode><testState>TEST</testState><testResults>1</testResults><testRequiredResults>0</testRequiredResults><testExcludedResults>0</testExcludedResults><testAutoResolvedResults>1</testAutoResolvedResults><testproviderTypes>WATCHLIST</testproviderTypes></testPayload> CASE 9/16/2020 9:45 9/16/2020 9:45 erutrt7-d726-4672-8599-83d21927bec5 0 5786765dfgdfgdfg System User USER_SYSTEM 0 0 <?xml version="1.0" encoding="UTF-8" standalone="yes"?><testCaseEventSummary><testTypes>WATCHLIST</testTypes><testResults>1</testResults></testCaseEventSummary>
I am to create table with above DDL but when i insert it throws error
But when i declare all data type as varchar i am able to insert rows into this table
Can you please suggest what i am missing .
This is how i am trying to load data into table
COPY INTO demo_db.public.app_event
FROM #my_s3_stage/
FILES = ('Event_data.csv')
file_format=(type='CSV');
I am to create table with above DDL but when i insert it throws error But when i declare all data type as varchar i am able to insert rows into this table
This kind of error message indicates that there is implicit conversion that fails.
Most likely for column AAPP_EVENT_TO_UTC_DT timestamp the value 9/16/2020 9:45 is not recoginized.
For providing date/timestamps: '2020-09-16 09:45:00'::timestamp could be used or TRY_TO_TIMESTAMP(string_expr, format) function providing specific format.

Getting ID into temp table variable on INSERT INTO ... OUTPUT ... INTO temp table

This is the sample procedure I am using.
create procedure PRO_ProcName
#description varchar(max),
#txn_no varchar
as
begin
declare #txn table (
id bigint,
description varchar(max),
txn_no varchar
);
declare #txn_id bigint;
insert into transactions
(
description,
txn_no
)
output
inserted.description,
inserted.txn_no
into #txn
values
(
#description,
#txn_no
)
select #txn_id = id from #txn;
end
I am getting an error like:
Column name or number of supplied values does not match table definition.
I know that it is because I have id field in my temporary table and it is not getting inserted in the insert into statement. I cannot give value for id because it is the auto increment primary key.
How can I tackle this situation and get id of inserted record into a variable?
The inserted table represents the data that exists in the target table after the insert - so it also includes the auto-generated values, whether they where generated by a default value definition or by an identity definition on the columns - so you need to add inserted.id to the output clause.
However, there are two more things wrong in your procedure.
The first and most important is the fact that you didn't specify a length to the #txn_no varchar parameter. SQL Server will implicitly specify the length of 1 char in this case.
The second is the fact that you are not specifying the columns list of #txn in the output clause.
Here is a improved version of your code with all these issues fixed:
create procedure PRO_ProcName
#description varchar(max),
#txn_no varchar(255) -- Note: I don't know the actual length you need
as
begin
declare #txn table (
id bigint,
description varchar(max),
txn_no varchar
);
declare #txn_id bigint;
insert into transactions
(
description,
txn_no
)
output
inserted.id,
inserted.description,
inserted.txn_no
into #txn(id, description, txn_no)
values
(
#description,
#txn_no
)
select #txn_id = id from #txn;
end
I cannot give value for id because it is the auto increment primary key.
No it isn't. You haven't declared it to be anything of the sort. So we need to fix that first:
declare #txn table (
id bigint IDENTITY PRIMARY KEY,
description varchar(max),
txn_no varchar
);
And then we fix it by specifying a column list in your INTO clause:
output
inserted.description,
inserted.txn_no
into #txn (description, txn_no)
It's always a good habit to specify column lists anyway.
Or if I've misinterpreted your question, and the id should be coming from transactions, then you just add inserted.id as another column in your OUTPUT clause. inserted represents that state of the table after the insert. So you can include columns from it in your OUTPUT clause even if you didn't specify them in the INSERT.

Error while inserting data with stored procedure in table with shared identity primary key

I've got a few tables linked together where data should be inserted to using a stored procedure. The tables are:
create table contactpersoon
(
contactpersoonnr integer identity(1,1),
klantnr integer,
naam varchar(50) not null,
telefoonnr varchar(10) not null,
emailadres varchar(50) not null,
constraint pk_contactpersoon
primary key(contactpersoonnr, klantnr),
constraint fk_contactpersoon_klantnr
foreign key(klantnr) references klant(klantnr)
)
create table klant
(
klantnr integer identity(1,1) primary key,
bedrijfsnaam varchar(50) not null
)
create table Logins
(
GebruikersNaam varchar(30),
Wachtwoord varchar(30),
Klantnr int,
MdwNr int,
constraint pk_logID primary key(GebruikersNaam),
constraint fk_klantnr foreign key(klantnr) references klant(klantnr),
constraint fk_mdwnr foreign key(mdwnr) references medewerker(mdwnr)
)
Stored procedure for adding data to these tables:
IF EXISTS (SELECT * FROM sys.objects WHERE type = 'P' AND name = 'spKlantAanmaken')
DROP PROCEDURE spKlantAanmaken
GO
Create Procedure spKlantAanmaken
(
#bedrijfsnaam as varchar(255),
#contactnaam as varchar(255),
#telnr as integer,
#email as varchar(255),
#gebruikersnaam as varchar(255),
#wachtwoord as varchar(255)
)
AS
Begin transaction
Declare #klantnr integer
Declare #contactpersoonnr integer
Insert into Klant Values (#klantnr, #bedrijfsnaam);
Insert into contactpersoon values(#contactpersoonnr, #klantnr, #contactnaam, #telnr, #email);
Insert into Logins values (#gebruikersnaam, #wachtwoord ,#klantnr, NULL);
Select * from contactpersoon
IF ##ERROR <> 0
BEGIN
ROLLBACK
RAISERROR ('Error tijdens uitvoeren van stap 2.', 16, 1)
RETURN
END
COMMIT
GO
I don't know if it is necessary to use these identity values in the inserts.
If I try this stored procedure I get the following error:
Msg 8101, Level 16, State 1, Procedure spKlantAanmaken, Line 923
An explicit value for the identity column in table 'Klant' can only be
specified when a column list is used and IDENTITY_INSERT is ON.
If I remove the identity values from the insert I get this error:
Msg 213, Level 16, State 1, Procedure spKlantAanmaken, Line 923
Column name or number of supplied values does not match table definition.
What am I doing wrong?
When you use Identity, the columns on which the identity is applied need not be in your INSERT statement VALUES. So edit your code like below
EDIT
It also seems you are missing out the columns you are trying to insert into
Insert into Klant (bedrijfsnaam) Values (#bedrijfsnaam)
Insert into contactpersoon (klantnr, contactnaam, telnr, email) Values (#klantnr, #contactnaam, #telnr, #email)
It seems all the answers saying the same thing so hope your issued is solved
Since you have identity columns, you must specify the list of columns to insert into, in your INSERT statement, and not supply a value for the identity column - like this:
Instead of
Insert into Klant Values (#klantnr, #bedrijfsnaam);
use
Insert into Klant(bedrijfsnaam) Values (#bedrijfsnaam);
and do this for all your INSERT operations.
This is a generally accepted "Best Practice" for any time you insert something into a table - it is recommend to always explicitly specify the list of columns in your table that you're inserting into (to avoid annoying errors and surprises).
Avoid the identity columns klantnr, contactpersoonnr in the INSERT query and explicitly define your column names:
So the below code will work in your case:
Insert into Klant(bedrijfsnaam) Values (#bedrijfsnaam);
Insert into contactpersoon(klantnr, naam, telefoonnr, emailadres) values(#klantnr, #contactnaam, #telnr, #email);
Just specify the column names AND the contents in the INSERT statement like:
INSERT INTO klant (bedrijfsnaam) VALUES ('XYZ');
If you don't specify the column name list, the SQL interpreter implies, you want the identity column, too. In this case you would want to set data for 2 columns, but only provide one content element, which explains the latter error message.
Edit these two lines in your SP
Insert into Klant (bedrijfsnaam)
Values (#bedrijfsnaam);
Insert into contactpersoon(klantnr,naam,telefoonnr,emailadres)
values(#klantnr, #contactnaam, #telnr, #email);
Provide a column list, excluding the identity columns in the insert statements

SQL server image data type value inserted is not same

I am inserting a value in the table having image datatype, value inserted is not same as that inserted
CREATE TABLE Products(
[Key] [nvarchar](40) NOT NULL,
[Data] [image] NOT NULL,
)
I am using the below statement
insert into Products values( '1','0xEC7D079C1CB5F5FFFACE74')
value inserted is '0x307845433744303739433143423546354646464143453734'
instead of '0xEC7D079C1CB5F5FFFACE74'
Is there any other way to insert an image value in the table?
You appear to be confusing a string with binary.
This is a string: '0xEC7D079C1CB5F5FFFACE74'
This is binary: 0xEC7D079C1CB5F5FFFACE74
[Also, why do you have a integer key declared as nvarchar(40) ??]
As #GarethD pointed out, the text, ntext, and image datatypes are on the deprecation list and you should avoid using them in new development work.

Inserting a row with SQL Server Management Studio results in ERROR

This is what I have
CREATE TABLE Saver(
SaverID INT NOT NULL PRIMARY KEY IDENTITY,
FirstName VARCHAR(10),
Surname VARCHAR(10),
[Address] VARCHAR(60),
Email VARCHAR(30),
Username VARCHAR(10),
[Password] VARCHAR(10),
CreditBalance INT,
);
I'm trying to insert data into my table with this:
INSERT INTO Customer
(SaverID,FirstName,Surname,[Address],Email,Username,[Password],CreditBalance)
VALUES (01,'David','Slavic','123 fake street','David#gmail.com','DJ','passcode',10.00);
I get this error:
Msg 544, Level 16, State 1, Line 1
Cannot insert explicit value for identity column in table 'Customer' when IDENTITY_INSERT is set to OFF.
I don't understand why? Please help
You should not insert value for SaverID, you have told the RDBMS to generate a value for it (you've done so with your CREATE statement): SaverID INT NOT NULL PRIMARY KEY IDENTITY.
Your primary key is auto increment, you can not insert a value on it
Omit the ID from your INSERT query:
INSERT INTO Customer
(FirstName,Surname,[Address],Email,Username,[Password],CreditBalance)
VALUES ('David','Slavic','123 fake street','David#gmail.com','DJ','passcode',10.00);

Resources