在示例 Java 项目中使用数据库的最简单方法? [英] Easiest Way to Use Database in Sample Java Project?

查看:71
本文介绍了在示例 Java 项目中使用数据库的最简单方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我先说:我的数据库经验很少.我了解数据库的概念以及如何在 Java 中使用数据库,但我不知道如何创建数据库,而且我对 SQL 的了解基本为零.

I'll preface this with: I have very little database experience. I understand the concept of a database and how to use a database within Java, but I have no idea how to create one and my knowledge of SQL is essentially zilch.

我正在创建一个示例项目,向我的公司展示 IntelliJ 的功能,希望他们能从 Eclipse 转换.我们公司的一大特色是数据库集成,所以我想展示一下数据库工具.为此,我需要在项目中建立一个数据库.它不需要很大、很花哨或很合适……它只需要在那里.它永远不会扩大规模.它永远不会超过 10 行和 4 或 5 列.

I am creating a sample project to show off the features of IntelliJ to my company, in the hopes they will convert from Eclipse. One of the big features for our company will be database integration, so I would like to show off the Database tools. To do this, I need a database in the project. It doesn't need to be big or fancy or proper... it just needs to be there. It will never scale up. It will never be more than 10 rows and 4 or 5 columns.

这是我的要求:

  • 通过Maven启动实例需要容易
  • 这不可能是 Derby(我们的 Maven 存储库中没有 Derby 驱动程序)
  • 它必须与 Hibernate 和 Spring 配合使用
  • 一切都必须通过 Maven 运行 - 没有特定于 IDE 的东西
  • 数据库内容需要是持久的,以便我可以将其推送到项目存储库(例如,不是在连接关闭后立即删除的内存数据库)

我怎样才能创建这个?如何使用数据库内容创建文件?如何通过 Maven 启动实例?如果它是类似 HSQLite 的东西,并且数据库内容存储在 *.sql 文件中,我如何使用单个 maven 命令自动启动实例并运行该文件?

How can I create this? How do I create the file with the DB content? How do I start the instance via Maven? If it is something like HSQLite and the DB content is stored in a *.sql file, how do I do I automate starting an instance and running the file with a single maven command?

这里的关键很简单.我想要一个不知道如何做到这一点的假人(像我一样)能够运行这个项目并为他或她自己尝试.

The key here is easy. I want a dummy (like me) with no idea how to do this to be able to run this project and try it for him or herself.

感谢您提供的任何帮助!

Thanks for any help that's out there!

大卫

推荐答案

您可以尝试将 sqllite 用于将数据持久化到文件的简单数据库.这里有一个 jdbc 驱动程序:https://bitbucket.org/xerial/sqlite-jdbc 以及使用说明.可以看到,指定连接的时候,传入了一个文件名.驱动程序本身可以通过 maven 下载.

You might try sqllite for a simple database that persists data to a file. There is a jdbc driver for it here: https://bitbucket.org/xerial/sqlite-jdbc along with instructions for use. You can see that when you specify the connection, you pass in a file name. The driver itself can be downloaded via maven.

似乎有一些关于您是否可以使用 hibernate 的问题:是否完全休眠支持 SQLite.看来值得一试.

It seems like there's some question as to whether you can use hibernate with it: Does Hibernate Fully Support SQLite. It seems like it might be worth a shot.

更复杂的一步是 hsqldb.我经常用它来测试内存中的休眠持久层(使用 mysql 或 oracle 的生产应用程序).所以我知道它适用于 spring/hibernate:http://hsqldb.org/.

One step up in complexity is hsqldb. I often use it for testing hibernate persistence layers in memory (with the production app using mysql or oracle). So I know that it works with spring/hibernate: http://hsqldb.org/.

玩得开心!

这篇关于在示例 Java 项目中使用数据库的最简单方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆