我有一些Java知识,这是我在大学学习期间获得的(不是主科)。从那时起我就不再用Java编程来谋生了。 最近我决定恢复编程技能,所以我用 Vaadin 开始了一些真正的 java web 项目。到目前为止,一些用户界面已经完成,现在我需要将数据保存在数据库中。 抱歉介绍太长,我需要你了解我的水平
问题: 我想在 Eclipse IDE 中将嵌入式数据库与 Vaadin 项目一起使用。我已经通过 Ivy 下载了 derby jar 文件并堆放在这里。所有教程都不教授如何将 Derby(任何)DB 链接到 Web 项目。
你们能给我一些线索吗?
最佳答案
您可以在分发包中找到使用 Embedded Derby 的应用程序示例。您可以在这里找到相关教程: https://db.apache.org/derby/papers/DerbyTut/embedded_intro.html
使用它与使用任何其他 jdbc 驱动程序一样简单,只是嵌入式数据库在同一 Java 进程中执行。
这是一个例子:
/*
* This connection specifies create=true in the connection URL to
* cause the database to be created when connecting for the first
* time. To remove the database, remove the directory derbyDB (the
* same as the database name) and its contents.
*
* The directory derbyDB will be created under the directory that
* the system property derby.system.home points to, or the current
* directory (user.dir) if derby.system.home is not set.
*/
String protocol = "jdbc:derby:";
String dbName = "derbyDB"; // the name of the database
props.put("user", "user1");
props.put("password", "user1");
Connection conn = DriverManager.getConnection(protocol + dbName
+ ";create=true", props);
// Then you can use jdbc classes to create and execute your queries
// For example :
Statement s = conn.createStatement();
// We create a table...
s.execute("create table location(num int, addr varchar(40))");
关于java - 嵌入式数据库、Java Web 项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29727375/