连接“计算机

编程入门 行业动态 更新时间:2024-10-22 17:19:24
本文介绍了连接“计算机-数据库-jpa"使用 MySQL 播放 2.1 示例应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在玩 computer-database-jpa (Java) Play Framework 2.1 示例应用程序.当我在内存数据库中使用 H2 时一切正常,但是当我想将应用程序与 MySQL 连接时遇到问题.

I'm playing with computer-database-jpa (Java) Play Framework 2.1 sample application. Everything works fine when I'm using H2 in memory database but I had problems when I want to connect the application with MySQL.

有些人遇到了同样的问题(帮助希望将示例应用程序连接到MySQL) 但没有解决方案.

Some one had the same problem (Help wanted getting sample app connected to MySQL) but there was no solution.

我添加了 mysql-connector (Build.scala):

I've added mysql-connector (Build.scala):

val appDependencies = Seq(
  ....
  "mysql" % "mysql-connector-java" % "5.1.18"
)

并编辑application.conf:

and edited application.conf:

db.default.url="jdbc:mysql://password:user@localhost/my-database"
db.default.driver=com.mysql.jdbc.Driver

当我启动应用程序并应用 1.sql(进化脚本)时,出现错误:

When I start the applications and apply 1.sql (evolution script) I get an error:

You have an error in your SQL syntax; check the manual that corresponds to
your MySQL server version for the right syntax to use near 'sequence company_seq
start with 1000' at line 1 [ERROR:1064, SQLSTATE:42000]

有人知道如何解决这个问题吗?

Does anyone have an idea how to solve the problem?

推荐答案

我找到了解决方案 - https://github/opensas/openshift-play2-computerdb.

I've found the solution - https://github/opensas/openshift-play2-computerdb.

进化脚本中使用的语法不符合MySQL:

Syntax used in evolution scripts isn't conform with MySQL:

添加了 engine=innodb,以启用参照完整性用自动增量替换 id 字段的序列将SET REFERENTIAL_INTEGRITY"命令替换为SET FOREIGN_KEY_CHECKS"用日期时间替换时间戳字段 将计算机数据拆分为 2.sql 和 3.sql 文件(避免在 mysql 上运行时出现错误) 从 Computer.list sql 查询中删除了最后一个空值"修改 Computer.insert 以跳过 id 字段(因为是由 mysql 自动分配的)

因为我玩的是 Java 而不是 Scala 版本,所以我要更改 Company.javaComputer.java 文件.我添加了 @GeneratedValue 注释:

Because I was playing with Java and not Scala version I'd to change Company.java and Computer.java files. I've added @GeneratedValue annotation:

@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
public Long id;

在这里你可以找到修改后的进化脚本:https://github/opensas/openshift-play2-computerdb/tree/master/conf/evolutions/default

Here you can find modified evolution scripts: https://github/opensas/openshift-play2-computerdb/tree/master/conf/evolutions/default

这篇关于连接“计算机-数据库-jpa"使用 MySQL 播放 2.1 示例应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-03-27 09:42:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/686700.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:计算机

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!