我試圖將數組[字節]插入到帶有scala和play framework的二進制數據類型colunm中,並在MariaDB上進行打滑。 但是,我得到了這個錯誤,並沒有插入數據。如何插入數組[字節]到二進制數據類型列與光滑和mariadb?
Execution exception
[MysqlDataTruncation: Data truncation: Incorrect string value: '\x85\x09\x9B\x08%B...' for column 'userID' at row 1]
數據是使用java.util.UUID的UUID。 將UUID轉換爲數組[Byte]由UUIDHelper.scala執行,即this code。
如何插入Array [Byte]數據到數據庫?
我的環境是這樣的。
數據庫:
MariaDB 10.1.16
MariaDB [test]> show full columns from user;
+-----------+--------------+-----------------+------+-----+---------+-------+---------------------------------+---------+
| Field | Type | Collation | Null | Key | Default | Extra | Privileges | Comment |
+-----------+--------------+-----------------+------+-----+---------+-------+---------------------------------+---------+
| userID | binary(16) | NULL | NO | PRI | NULL | | select,insert,update,references | |
| firstName | varchar(254) | utf8_general_ci | YES | | NULL | | select,insert,update,references | |
| lastName | varchar(254) | utf8_general_ci | YES | | NULL | | select,insert,update,references | |
| fullName | varchar(254) | utf8_general_ci | YES | | NULL | | select,insert,update,references | |
| email | varchar(254) | utf8_general_ci | YES | | NULL | | select,insert,update,references | |
| avatarURL | varchar(254) | utf8_general_ci | YES | | NULL | | select,insert,update,references | |
+-----------+--------------+-----------------+------+-----+---------+-------+---------------------------------+---------+
用戶ID是UUID colunm。
播放華而不實的配置:
slick.dbs.default.driver="slick.driver.MySQLDriver$"
slick.dbs.default.db.driver="com.mysql.jdbc.Driver"
發揮和Scala版本:
scalaVersion := "2.11.7"
libraryDependencies ++= Seq(
"com.mohiva" %% "play-silhouette" % "3.0.2",
"org.webjars" %% "webjars-play" % "2.4.0-1",
"net.codingwell" %% "scala-guice" % "4.0.0",
"net.ceedubs" %% "ficus" % "1.1.2",
"com.adrianhurt" %% "play-bootstrap3" % "0.4.4-P24",
"com.mohiva" %% "play-silhouette-testkit" % "3.0.2" % "test",
specs2 % Test,
"com.typesafe.play" %% "play-slick" % "1.0.1",
"com.typesafe.play" %% "play-slick-evolutions" % "1.0.1",
//"com.h2database" % "h2" % "1.4.188",
"mysql" % "mysql-connector-java" % "5.1.39",
cache,
evolutions,
filters
)
依靠[本文檔](http://slick.lightbend.com/doc/3.0.1/schemas.html?highlight=uuid),我想我們可以使用Array [Byte](和java.util。 UUID)。 但是,當我使用Array [Byte]和java.util.UUID時,出現了上述錯誤。 –