Database "mem:h2" not found, either pre-create it or allow remote database creation (not recommended in secure environments) [90149-210] 90149/90149 解決


1.4.198 (2019-02-22) 版本開始,H2不再自動創建數據庫,很難在網上找到有解決方案,故down了源碼

Connection to jdbc:h2:tcp://0.0.0.0:6666/./aika failed. [90149][90149] Database "/home/Hex/IdeaProjects/h2database/h2/aika" not found, either pre-create it or allow remote database creation (not recommended in secure environments) [90149-200]

翻閱源碼在

tutorial.html中有這么一段話(官方是不推薦這么做的,但是我們有時候用h2內嵌如果不能自動建庫會很不方便)

    If you really need to allow remote database creation, you can pass <code>-ifNotExists</code> parameter to
    TCP, PG, or Web servers (but not to the Console tool).
    Its combination with <code>-tcpAllowOthers</code>, <code>-pgAllowOthers</code>, or <code>-webAllowOthers</code>
    effectively creates a remote security hole in your system, if you use it, always guard your ports with a firewall
    or some other solution and use such combination of settings only in trusted networks.

 

在啟動服務的時候添加  -ifNotExists 就可以了。

    package org.h2.start;
     
    import org.h2.tools.Server;
     
     
    public class StartServer {
     
        public static void main(String[] args) throws Exception{
            Server server = Server.createTcpServer("-tcp", "-tcpAllowOthers","-ifNotExists", "-tcpPort",
                    "6666");
     
            server.start();
            while (true){
                Thread.sleep(10000);
            }
        }
    }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM