简体   繁体   English

为什么我刚刚实现的H2数据库出现“数据库可能已在使用:空”错误?

[英]Why Am I Getting a “Database may be already in use: null” Error for H2 Database That I Just Implemented?

I am putting together a small Java app that I want to use an embedded database for so I'm using H2. 我正在整理一个小型Java应用程序,我想使用嵌入式数据库,所以我使用的是H2。 I followed the tutorial to set it up, and ran a test for the first run to see if it worked. 我按照教程进行了设置,并为首次运行进行了测试以查看其是否有效。 I had never run it before so it could not have actually been in use, still when I ran it the first time it threw the following error. 我以前从未运行过它,因此它实际上并没有被使用过,即使在我第一次运行它时,它也出现以下错误。

org.h2.jdbc.JdbcSQLException: Database may be already in use: null. org.h2.jdbc.JdbcSQLException:数据库可能已在使用中:null。 Possible solutions: close all other connection(s); 可能的解决方案:关闭所有其他连接; use the server mode [90020-196] 使用服务器模式[90020-196]

Here's what I've written. 这是我写的。

It's attached to a submit button the form. 它附在表单的提交按钮上。

    JButton btnRegisterupdate = new JButton("Register/Update");
    btnRegisterupdate.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0){

            try {
                Class.forName("org.h2.Driver");
                Connection connection = DriverManager.getConnection("jdbc:h2:~/test", "sa", " ");

                JOptionPane.showMessageDialog(null, "Connection Awesome");
            } catch (ClassNotFoundException  | SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }  

        }
    });
    btnRegisterupdate.setBounds(10, 243, 146, 23);
    frame.getContentPane().add(btnRegisterupdate);
}
}

OK, so the instructions for this require the user to go to the login page and click connect. 确定,因此有关此说明的要求用户进入登录页面并单击“连接”。 This remains open unless you click disconnect. 除非您单击断开连接,否则它将保持打开状态。 Nowhere does it say in the tutorial. 在本教程中无处说明。 Once you click connect to set it up, click disconnect in the browser version. 单击“连接”进行设置后,请在浏览器版本中单击“断开连接”。

That's what you have to do. 那就是你要做的。

Click connect to set it up, it takes you to another screen where you can create tables, and so on, but when you're done in there, disconnect. 单击“连接”进行设置,它会转到另一个屏幕,您可以在其中创建表,依此类推,但是在其中完成后,请断开连接。

Run the executable jar file in the bin folder. 运行bin文件夹中的可执行jar文件。 This will open up in a browser. 这将在浏览器中打开。 Click on the Server Setting drop down and change it to Generic H2(Server). 单击服务器设置下拉菜单并将其更改为通用H2(服务器)。 Previously it was set to Generic H2(Embedded) that was why it didnt work for me. 以前将其设置为通用H2(嵌入式),这就是为什么它对我不起作用的原因。

暂无
暂无

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

相关问题 H2 数据库错误:数据库可能已在使用中:“已被另一个进程锁定” - H2 database error: Database may be already in use: "Locked by another process" H2数据库中的问题可能已在使用中 - Having issues in H2 Database may be already in use 为什么我的H2数据库/ Spring Boot应用程序出现JdbcSQLException(非十六进制字符)? - Why am I getting JdbcSQLException (non-hex characters) with my H2 database / Spring boot application? 为什么在尝试通过URL“jdbc:h2:test”创建数据库时收到错误 - Why am I receiving an error when trying to create the database by the URL of “jdbc:h2:test” 我正在尝试使用 H2 内存数据库和自定义 @GenericGenerator 策略,但在内部我的 customeId 生成器没有被调用 - I am trying to use H2 in-memory database and custom @GenericGenerator strategy but internally my customeId generator is not getting called 嵌入式H2:数据库的Tomcat WebApp可能已在使用中:“被另一个进程锁定” - Tomcat WebApp with embedded H2 : Database may be already in use: “Locked by another process” 内存数据库中的H2在列名和我要使用的值之间变得混乱 - H2 in memory database is getting confused between column name, and the value I want to use 如何在 Laravel 中使用 H2 数据库? - How can I use H2 database with laravel? 我无法连接到 H2 数据库 - i can't connect to the H2 database H2数据库控制台错误 - H2 database console error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM