简体   繁体   English

将数据(字符串)存储在数据库中

[英]Store data(strings) in database

I have a Vector < String >. 我有一个向量<String>。 Now i want to store those Strings in database. 现在我想将那些字符串存储在数据库中。 But i have one "but"! 但是我有一个“但是”! The program user mustn't install anything else except J2RE, he will just copy program to his computer and run. 程序用户除了J2RE之外,不能安装其他任何东西,他只会将程序复制到计算机上并运行。 Does java has such kind of database? java是否有这种数据库?

PS Previously i think about object serialization or just simple text\\xml file but according to the task it must be database... So user just copy my program and run, without installing any additional software, except J2RE. PS以前,我考虑对象序列化或只是简单的text \\ xml文件,但根据任务它必须是数据库...因此用户只需复制我的程序并运行,就无需安装任何其他软件(J2RE除外)。

I think HSQLDB is the right choice for your problem. 我认为HSQLDB是解决您的问题的正确选择。 You just need the HSQLDB JAR in your classpath and then use the file-based database configuration 您只需要在类路径中使用HSQLDB JAR,然后使用基于文件的数据库配置

You can embed Apache Derby in your application. 您可以在应用程序中嵌入Apache Derby。 This will run on a JRE installation. 这将在JRE安装上运行。

The only thing I know of is JavaDB, but I don't know if that's included in J2RE. 我唯一知道的是JavaDB,但我不知道J2RE中是否包含该代码。 For more info on JavaDB see JavaDB 有关JavaDB的更多信息,请参见JavaDB。

Edit After reading on the JavaDB site it seems it's only included in the JDK, which I assume would be not sufficient for you. 编辑在JavaDB站点上阅读后,似乎只包含在JDK中,我认为这对您来说还不够。

Why the requirement for a database? 为什么需要数据库? You have 1 Vector - is there any other data that is linked to each String? 您有1个Vector-是否有其他数据链接到每个String? If you just have to search for Strings in the Vector, you can do that without a database. 如果只需要在Vector中搜索字符串,则无需数据库即可完成此操作。 Ordering the list, searching for substring matches, etc can all be done using Java string functions. 使用Java字符串函数可以对列表进行排序,搜索子字符串匹配项等。 Even if the list contians 100,000 thousand Strings, it should still be fast. 即使列表包含100,000万个String,它仍然应该很快。

JavaDB and Derby are very closely related. JavaDB和Derby密切相关。 JavaDB is the Sun distribution of Derby. JavaDB是Derby的Sun发行版。 You can get Derby directly from the Apache web site ( http://db.apache.org/derby ) and embed it directly into your application, and both JavaDB and Derby require only the JRE in order to run. 您可以直接从Apache网站( http://db.apache.org/derby )获得Derby,并将其直接嵌入到您的应用程序中,并且JavaDB和Derby都只需要JRE即可运行。

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

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