java - 嵌入式数据库、Java Web 项目

标签 java eclipse web-applications derby

我有一些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/

相关文章:

java - 构建路径指定执行环境J2SE-1.5。工作区中没有安装与此环境严格兼容的 JRE

javascript - 如何在不在每个 JS 文件中添加的情况下调用所有文件的通用 JavaScript 函数?

Java JSON 到数组

java - 我的数组列表正在向自身添加数千个对象

java - 如何调试 web 应用程序中的 jar

java - 无法使用自定义注释文件创建 javadoc(无法执行二进制文件)

java - 在java中调用方法并在for循环中递增数组

eclipse - 如何使 Eclipse 文件搜索不包含 svn 目录?

html - 响应式设计,强调视网膜显示和桌面。 Sprite 和 JS : what to sacrifice?

java - Tomcat Web 应用程序更改部署目录