java 如何将 sqLite 数据库连接到 netbeans
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34880061/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to connect sqLite database to netbeans
提问by user5809644
I want to create some applications in Java netbeans using sqLite manager. i had done the following steps.
我想使用 sqLite 管理器在 Java netbeans 中创建一些应用程序。我已经完成了以下步骤。
- I have done plugin to Mozilla Firefox a sqLite-manger database
- I have create database calling "mydb".
- I have create a table with 2 values fname , lname.
I got mydb.sqlite file.
In netbeans library i have add jar file calling sqlite-jdbc 3.7.2 jar
then i copy the file mydb.sqlite from the folder and paste into netbeans project folder .
- I want to connect with my project calling "test" in netbeans.
- 我已经为 Mozilla Firefox 做了一个 sqLite-manger 数据库插件
- 我创建了名为“mydb”的数据库。
- 我创建了一个包含 2 个值 fname 和 lname 的表。
我得到了 mydb.sqlite 文件。
在 netbeans 库中,我添加了调用 sqlite-jdbc 3.7.2 jar 的 jar 文件
然后我从文件夹中复制文件 mydb.sqlite 并粘贴到 netbeans 项目文件夹中。
- 我想连接我在 netbeans 中调用“test”的项目。
how to connect with netbeans application
如何连接netbeans应用程序
采纳答案by simar
Here is example http://www.tutorialspoint.com/sqlite/sqlite_java.htm
这是示例http://www.tutorialspoint.com/sqlite/sqlite_java.htm
Most important part is jdbc url to create connection:
最重要的部分是 jdbc url 来创建连接:
jdbc:sqlite:mydb.sqlite
This url assumes that test.db located in same directory, u application starts from. But u can put path to certain db.
此 url 假设 test.db 位于同一目录中,您的应用程序从该目录开始。但是你可以把路径放在某个数据库上。
For example:
例如:
jdbc:sqlite:c:/temp/sqlite/mydb.sqlite
If u distribute u application when there u manage some initialization. Actually u have to set environment for u application before start. Let's say u have good working application in netbeans and u copy application to another machine. Configure environment for application to make it same as actual working application instance in netbeans. Question u should think about
如果你在那里管理一些初始化时分发你的应用程序。实际上,您必须在开始之前为您的应用程序设置环境。假设您在 netbeans 中有良好的工作应用程序,并且您将应用程序复制到另一台机器。为应用程序配置环境,使其与 netbeans 中的实际工作应用程序实例相同。你应该考虑的问题
- What path to database to use relative or absolute?
- Where database location on filesystem (absolute path to database)?
- Where directory from which application starts (relative path to database)?
- 使用相对或绝对的数据库路径是什么?
- 文件系统上的数据库位置在哪里(数据库的绝对路径)?
- 应用程序从哪个目录开始(数据库的相对路径)?
Useful information:
有用的信息:
- jdbc driver will create database mysql.sqlite if it doesn't exists (path to directory "c:/temp/sqlite"should be real) and after u can recreate necessary structure of database.
- u can use System Properties https://docs.oracle.com/javase/tutorial/essential/environment/sysprop.htmlespecially user.dirand user.hometo set predefined location of u database (create database in there or copy existing database file)
- jdbc 驱动程序将创建数据库 mysql.sqlite 如果它不存在(目录“c:/temp/sqlite”的路径应该是真实的),然后你可以重新创建数据库的必要结构。
- 你可以使用系统属性https://docs.oracle.com/javase/tutorial/essential/environment/sysprop.html特别是user.dir和user.home来设置你的数据库的预定义位置(在那里创建数据库或复制现有数据库文件)