H2。将字符串插入VARBINARY(255)

时间:2018-02-17 20:32:39

标签: sql database insert h2 varbinary

我在将数据添加到h2表时遇到了问题VARBINARY(255)

USER

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

尝试这样做:

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

和这个

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

还有很多其他的变化。所有在SQL语句

中抛出“语法错误”

打破我的想法......请帮忙!

1 个答案:

答案 0 :(得分:1)

您可以使用H2' STRINGTOUTF8()功能。

以下是您的示例

var t = $('#datatables').DataTable();

//-------------------------INSERT ROOM START----------------------------
$("[name='add-room-submit']").click(function () {

    var r_name = document.getElementById('room-name').value;
    var r_plan = document.getElementById('image-path').value;

    t.row.add([
               '<div class="img-container">' +
               '<img src="../../assets/img/room-plan/' + r_plan + '" alt="..." id="imgsrc">' +
               '</div>'
               ,
               r_name.toUpperCase(),
               '<div class="text-right">' +
               '<a href="#" class="btn btn-simple btn-warning btn-icon edit" data-toggle="modal" data-target="#myModal"><i class="fa fa-edit"></i></a>' +
               '<a href="#" class="btn btn-simple btn-danger btn-icon remove" ><i class="fa fa-times"></i></a>' +
               '</div>'
    ]).draw(false);

//addition

   var oTable = $('#datatables').dataTable();
   aData = oTable.fnGetData();
   var ndx = 0;
   var count = 0;
   $(aData).each(function () {       
    if ( r_name.toUpperCase() == oTable.fnGetData()[ndx][1] ) {
        count++;
    }
    ndx++;
});
if (count > 1) {
    alert('Warning!');
}

//addition

});
//-------------------------INSERT ROOM END----------------------------

$('#add-room-submit').click();