简体   繁体   English

用数据库开发Java应用程序

[英]Developing a Java Application with database

Sorry for this trivial question, but I am new to programming and I wanted to create a Java app that can be distributed to other computers without having to install database on that computer. 抱歉,这个琐碎的问题很严重,但是我是编程新手,我想创建一个Java应用程序,可以将该Java应用程序分发到其他计算机,而不必在该计算机上安装数据库。

The app is similar to an address book app where you store details about a person. 该应用程序类似于地址簿应用程序,您可以在其中存储有关某人的详细信息。 Is there a way to create something like that using netbeans which does not require a database or is there any other way to go about it.. 有没有一种方法可以使用netbeans创建类似的东西,而不需要数据库,或者有其他方法可以解决这个问题。

I have searched for answers, but I guess I am not searching for the right keywords which I'd appreciate if someone could enlighten me with. 我已经在寻找答案,但是我想我并不是在寻找合适的关键词,如果有人可以启发我,我将不胜感激。

PS: I know how to create an app like that in netbeans which is connected to a database (Mysql or Postgresql) but they cannot be moved from one computer to other? PS:我知道如何在连接数据库(Mysql或Postgresql)的netbeans中创建类似的应用程序,但是无法将它们从一台计算机移动到另一台计算机? Or can it be? 还是可以? I don't know. 我不知道。

Thanks you in advance.. 预先谢谢你..

When I want to make a Java program relying on a database and which is lightweight and which doesn't appear to have any other dependencies than a JVM, I use Apache Derby (JavaDB). 当我要使Java程序依赖于数据库并且重量轻并且似乎没有除JVM之外的任何其他依赖关系时,我使用Apache Derby (JavaDB)。

It is a pure Java database engine which you can embed in your Java application. 它是一个纯Java数据库引擎,您可以将其嵌入Java应用程序中。 Very small footprint. 占地面积很小。 I usually package the program with a SQL file for creating the database structure and another one for populating it. 我通常将该程序与一个用于创建数据库结构的SQL文件打包在一起,并使用另一个文件对其进行打包。 Worth taking a look IMO. 值得一看IMO。

EDIT: Just saving you the search... If you try DerbyDB, there is a little something you want to know (in case you also have that syndrome of not reading manuals)... When you close Derby, it throws exceptions if it went wrong AND if it went well. 编辑:只是为您节省了搜索...如果尝试DerbyDB,您需要了解一些知识(以防您还有不阅读手册的综合症)...关闭Derby时,如果它抛出异常出错了,如果一切顺利。 You'll receive exceptions with exception.getSQLState().equals("08006") and "XJ015" . 您将收到带有exception.getSQLState().equals("08006")"XJ015" These are for successful shutdown; 这些用于成功关闭; don't mind them. 不要介意他们。 On connection to Derby, you'll get exception.getErrorCode() == 40000 if the database was not yet created; 如果尚未创建数据库,则在连接到Derby时,将获得exception.getErrorCode() == 40000否则,您将获得exception.getErrorCode() == 40000 just create it. 只需创建它。 (These exceptions are all SQLException instances.) (这些异常是所有SQLException实例。)

If your application has a database back-end, then you will require database software on either the computer where the application is running, or on a remote server. 如果您的应用程序具有数据库后端,那么您将需要在运行该应用程序的计算机或远程服务器上使用数据库软件。

If you want the application and database to be portable, you can use something like SQLite (an embedded SQL database engine) or even flat files. 如果您希望应用程序和数据库具有可移植性,则可以使用诸如SQLite (嵌入式SQL数据库引擎)之类的文件,甚至可以使用平面文件。

您不必将数据库移动到任何计算机,您可以做的是编写一些SQL脚本来生成应用程序所需的表(并在必要时填充),它可以在任何计算机上工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM