2016-04-11 117 views
3

我是Ubuntu的新手,我刚安装在电脑上。我安装了Samba并共享了文件夹“/ samba”和“/ hd”。我下载并安装了Firebird并复制了我在Windows上创建的数据库并将其放入“/ samba”中。这是我的Java代码:无法连接到Firebird(Ubuntu)

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 

如果我去 “/桑巴”,然后键入:

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

这工作完全正常,我可以选择,删除,更新,插入......没有任何问题。

如果我用我的IBExpert Windows机器连接到我的数据库,在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 

但它连接。我可以选择,删除,更新...

+0

也许你会需要允许访问为IBExpert,你的Java应用程序的目录... – Majkl

+0

我做了“chmod 755/samba -R”,错误仍然存​​在。 – Bolaum

回答

1

问题是您在连接字符串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专家和Flamerobin,他们似乎是无关的,应该真的是单独的问题。 IB专家问题似乎是您指定了无法解析为(IPv4)IP地址的主机名(Server-Test),或者服务器不接受连接请求。原因可能是Firebird服务没有监听该IP地址;在默认情况下,Firebird只在本地主机上侦听。 Flamerobin错误听起来像Flamerobin中的错误(或者您指定了不支持的连接字符集(?))。

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

+0

这工作。谢谢!现在我可以专注于解决我的IBExpert问题。 – Bolaum

0

关于IBExpert:这个截图是例如如何看待登记表与Ubuntu的连接:

enter image description here