简体   繁体   English

如何在Java中下载和解析SQL文件

[英]How to download and parse an sql file in java

I'm learning java/android development and I have an idea of an app that I want to make. 我正在学习Java / Android开发,并且对要制作的应用程序有个想法。 I want to make an app that displays a list of upcoming games (just an example) that I keep updating frequently. 我想制作一个可以显示我会经常更新的即将到来的游戏列表的应用程序(仅作为示例)。 And in order to do that, it downloads a database file (or read it directly without downloading) and parse it to display the information each time the user opens the app. 为了做到这一点,它会下载一个数据库文件(或直接读取而不下载),并在每次用户打开该应用程序时解析它以显示信息。

I searched a lot and I didn't find any way to do it. 我搜索了很多东西,但没有找到任何方法。 I'll be thankful if someone tells me how. 如果有人告诉我怎么办,我会很感激。 I know that it's possible to use a RSS feed but I want to use database if possible. 我知道可以使用RSS提要,但我想尽可能使用数据库。 PS: sorry if my English is terrible. PS:对不起,如果我的英语不好。

I would recommend SQL database H2 . 我会推荐SQL数据库H2 Simply include the .jar with your project (follow the website installation instructions) and use it in your code with: 只需将.jar包含在您的项目中(按照网站安装说明进行操作),并在代码中使用以下代码即可:

Class.forName("org.h2.Driver");
Connection con = DriverManager.getConnection("jdbc:h2:"+path_to_database);
con.createStatement().execute("CREATE TABLE games(name VARCHAR(80))");
con.createStatement().execute("INSERT INTO games(name) VALUES('Halo 3')");
// etc...

Their documentation is pretty comprehensive to get you started with reading and writing from the database. 他们的文档非常全面,可帮助您开始从数据库进行读取和写入。

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

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