嵌入式数据库,Java Web 项目

Embedded DB, Java Web Project

我有一些Java知识,是我在大学学习期间得到的(不是主科)。从那以后,我就不再以 Java 编程为生了。 最近我决定恢复编程技能,所以我用 Vaadin 开始了一些真正的 java 网络项目。到目前为止,一些 UI 已经完成,现在我需要在数据库中保存数据。 抱歉介绍太长了,我需要你了解我的水平

问题: 我想在 Eclipse IDE 中将嵌入式数据库与 Vaadin 项目一起使用。我已经通过 Ivy 下载了 derby jar 文件,并堆放在这里。所有教程都没有教如何 link Derby(任何)DB 到 Web 项目。

你们能给我一些线索吗?

您可以在分发包中找到使用嵌入式 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))");