如何制作.jar文件读取数据库和序列化.txt文件?
我正在尝试从程序中使用SQLITE数据库和序列化的读/写文件系统来制作可执行的.jar文件,以存储该程序。我们能够制作一个可执行的.jar文件,但是它没有从我们在程序中编写的任何数据库或文件系统中读取。有人知道该怎么做吗?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
“从数据库中读取.jar文件”当您拥有几乎完成的Java或Kotlin(或Scala)程序时。
我认为您的问题是编写一个程序需要什么。
为此,您必须考虑数据库应该能够处理的内容。
从文件系统中读取
光盘上的文本文件非常基本,但是如果应用程序只是读/写一些持久状态,则可能就足够了。为此,Java API拥有您需要的一切,请查看 baeldung- nio 。
从数据库中读取
如果您需要交易或支持持续存储的多个应用程序,则数据库将是更明智的方法。
尽管Java API再次为您提供所需的一切(例如)您需要从某种意义上重新发明轮子。更容易的是依靠 or-mapper 喜欢 a href =“ https://hibernate.org/orm/” rel =“ nofollow noreferrer”> hibernate 或 jooq 。
为了撰写企业Java软件,您可以使用
"To make a .jar file read from a database" when you have a Java or Kotlin (or Scala) program which does that you are almost done, you just have to compile it and which provides you a .jar file which does exactly that.
I think your question is what does it take to write a program that does it.
For that you have to think about what your database should be able to handle.
Read from filesystem
A text file on a disc is very rudimentary but might suffice if the application is just to read/write some persisted state. For that the Java API has all you need, take a look at Baeldung - read from file via NIO.
Read from database
If you need transactions or support for multiple applications working with the persisted storage, a database would be the more sensible thing to use.
Although the Java API again provides you everything you need for that (e.g.Processing SQL Statements with JDBC) you would need to reinvent the wheel in a sense. The easier thing would be to rely on an OR-mapper like Hibernate or JOOQ.
For writing enterprise Java software you could overengineer it with Spring-Boot JPA.