无法连接到 Firebird (Ubuntu)

Can't connect to Firebird (Ubuntu)

我是 Ubuntu 的新手,我刚刚将它安装在计算机上。我安装了 Samba 并共享文件夹“/samba”和“/hd”。我下载并安装了 Firebird 并复制了我在 Windows 上创建的数据库并将其放入“/samba”。这是我的 Java 代码:

public static Connection getConnection() throws SQLException {
        Connection connection = null;
        try {
            Class.forName("org.firebirdsql.jdbc.FBDriver");
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
        connection = DriverManager.getConnection("jdbc:firebirdsql://localhost:3050/samba/LNX.FDB", "sysdba",
                "masterkey");
        return connection;
    }

    public static void main(String[] args) throws SQLException {
        getConnection();
    }

我收到这个错误:

Exception in thread "main" org.firebirdsql.jdbc.FBSQLException: GDS Exception. 335544344. I/O error during "open" operation for file "samba/LNX.FDB"
Error while trying to open file
null
    at org.firebirdsql.jdbc.FBDataSource.getConnection(FBDataSource.java:120)
    at org.firebirdsql.jdbc.AbstractDriver.connect(AbstractDriver.java:136)
    at java.sql.DriverManager.getConnection(DriverManager.java:571)
    at java.sql.DriverManager.getConnection(DriverManager.java:215)
    at br.com.ipsnet.jdbc.ConnectionFactory.getConnection(ConnectionFactory.java:16)
    at br.com.ipsnet.jdbc.ConnectionFactory.main(ConnectionFactory.java:22)
Caused by: org.firebirdsql.gds.GDSException: I/O error during "open" operation for file "samba/LNX.FDB"
Error while trying to open file
null
    at org.firebirdsql.gds.impl.wire.AbstractJavaGDSImpl.readStatusVector(AbstractJavaGDSImpl.java:2098)
    at org.firebirdsql.gds.impl.wire.AbstractJavaGDSImpl.receiveResponse(AbstractJavaGDSImpl.java:2048)
    at org.firebirdsql.gds.impl.wire.AbstractJavaGDSImpl.internalAttachDatabase(AbstractJavaGDSImpl.java:463)
    at org.firebirdsql.gds.impl.wire.AbstractJavaGDSImpl.iscAttachDatabase(AbstractJavaGDSImpl.java:411)
    at org.firebirdsql.jca.FBManagedConnection.<init>(FBManagedConnection.java:105)
    at org.firebirdsql.jca.FBManagedConnectionFactory.createManagedConnection(FBManagedConnectionFactory.java:509)
    at org.firebirdsql.jca.FBStandAloneConnectionManager.allocateConnection(FBStandAloneConnectionManager.java:65)
    at org.firebirdsql.jdbc.FBDataSource.getConnection(FBDataSource.java:118)
    ... 5 more

如果我转到“/samba”并输入:

isql-fb
connect "localhost:/samba/LNX.FDB" user 'SYSDBA' password 'masterkey';

它工作得很好,我可以 select、删除、更新、插入...完全没有问题。

如果我在 Windows 机器上使用 IBExpert 连接到我在 Ubuntu 中的数据库,它说:

Unable to complete network request to host "Server-Test".
Failed to estabilish connection.

如果我使用 Flamerobin,它会显示:

An assertion failed!

../src/common/strconv.cpp(3031): assert "Assert failure" failed in wxCSConv(): invalid encoding value in wxCSConv ctor

但它连接。我可以 select、删除、更新...

问题是您在连接字符串 jdbc:firebirdsql://localhost:3050/samba/LNX.FDB 中指定的路径是 samba/LNX.FDB,而不是 /samba/LNX.FDB。相对路径取决于平台、用户和 Firebird 配置。

Jaybird release notes 中所述,您需要使用 jdbc:firebirdsql://localhost:3050//samba/LNX.FDB:

On Linux the root / should be included in the path. A database located on /opt/firebird/db.fdb should use the URL below (note the double slash after port!).

jdbc:firebirdsql://host:port//opt/firebird/db.fdb

或者,您可以定义一个别名并使用它。

至于您关于 IB Expert 和 Flamerobin 的问题,它们似乎是无关的,应该是单独的问题。 IB Expert 问题似乎是您指定的主机名 (Server-Test) 无法解析为 (IPv4) IP 地址,或者服务器不接受连接请求。原因可能是 Firebird 服务没有监听该 IP 地址;在 Ubuntu 默认情况下,Firebird 仅在本地主机上侦听。 flamerobin 错误听起来像是 Flamerobin 中的错误(或者您正在指定不受支持的连接字符集(?))。

关于您使用 samba 和使用网络共享:不要将 Firebird 数据库放在网络共享上。访问网络共享上的 Firebird 数据库(尤其是从多个服务器),可能会损坏数据库。如果你想从多个主机访问一个 Firebird 数据库,那么你需要使用一个 Firebird 服务器并通过它连接。

关于 IBExpert:此屏幕截图是如何查看注册表格以连接 ubuntu 的示例: