2

I have problems with adding data to h2 table, into a column of type VARBINARY(255).

Table USER

 ID BIGINT(19) NOT NULL auto_increment
 USERNAME VARCHAR(255) NOT NULL
 PASSWORD VARCHAR(255) NOT NULL
 ROLES VARBINARY(255) NOT NULL

Trying to do this:

INSERT INTO USER (username, password, roles) 
VALUES ('admin', '123', 'ROLE_ADMIN');

and this

INSERT INTO USER (username, password, roles) 
VALUES('admin', '123', CONVERT('ROLE_ADMIN', VARBINARY(255));

and a lot of another variations. All throw a "Syntax error" in SQL statement

Break my mind... Help please!

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

1 Answers1

3

You can use H2's STRINGTOUTF8() function.

Here is what your example would look like

INSERT INTO USER (username, password, roles) 
VALUES('admin', '123', STRINGTOUTF8('ROLE_ADMIN'));