简体   繁体   English

与 java 的 Firebird 连接

[英]Firebird connection with java

I have installed Firebird 2.1 on windows Xp and using firebirdsql.jdbc-2.1.6 driver to connect with java. Code:我已经在 windows Xp 上安装了 Firebird 2.1,并使用 firebirdsql.jdbc-2.1.6 驱动程序连接到 java。代码:

Class.forName("org.firebirdsql.jdbc.FBDriver"); 

connection = DriverManager.getConnection(
    "jdbc:firebirdsql://localhost/3050//C:/firebird/database/EMPLOYEE.FDB", 
    "test","test"); 

I am getting following error:我收到以下错误:

Caused by: org.firebirdsql.jdbc.FBSQLException: GDS Exception. 335544375.
unavailable database 
Reason: unavailable database at 
org.firebirdsql.jdbc.FBDataSource.getConnection(FBDataSource.java:122) at 
org.firebirdsql.jdbc.FBDriver.connect(FBDriver.java:140) at 
java.sql.DriverManager.getConnection(DriverManager.java:525) at 
java.sql.DriverManager.getConnection(DriverManager.java:171)

Please help.请帮忙。

Problem solved: Actually I had problem with jar file that I got from问题已解决:实际上,我从中获得的 jar 文件有问题

http://mirrors.ibiblio.org/pub/mirrors/maven2 http://mirrors.ibiblio.org/pub/mirrors/maven2

I downloaded jaybird-full-2.1.6.jar from firebird offical website and problem got solved.我从 firebird 官方网站下载了 jaybird-full-2.1.6.jar,问题解决了。

Correct URL is正确的 URL 是

"jdbc:firebirdsql://localhost:3050/C:\\firebird\\database\\EMPLOYEE.FDB"

I tried this URL earlier also but it was not working beacuse of jar issue.我之前也尝试过这个 URL,但由于 jar 问题,它无法正常工作。

As @Thorbjørn Ravn Andersen observes, your Jaybird JDBC URL is incorrect. 正如@ThorbjørnRavnAndersen所观察到的,您的Jaybird JDBC URL不正确。 The syntax is jdbc:firebirdsql:[host[/port]:]<database> . 语法是jdbc:firebirdsql:[host[/port]:]<database> You need a colon between the host/port and the database path. 您需要在主机/端口和数据库路径之间使用冒号。 Perhaps something like this: 也许是这样的:

"jdbc:firebirdsql://localhost/3050:C:\\firebird\database\EMPLOYEE.FDB"

Oops, I left in the leading slashes; 哎呀,我留下了领先的斜线; try this: 试试这个:

"jdbc:firebirdsql:localhost/3050:C:\\firebird\database\EMPLOYEE.FDB"

Addendum: You might run through the common errors list. 附录:您可能会浏览常见错误列表。 Also, my firebird database files end in .fdb , but the FAQ mentions .gdb . 另外,我的firebird数据库文件以.fdb结尾,但FAQ提到.gdb It can't hurt to check. 检查不会有害。

From https://www.firebirdsql.org/file/documentation/drivers_documentation/java/faq.html#pure-java-default 来自https://www.firebirdsql.org/file/documentation/drivers_documentation/java/faq.html#pure-java-default

Default URL format: 默认网址格式:

"jdbc:firebirdsql://host[:port]/<database>"

Deprecated, but still supported legacy URL format: 已弃用,但仍支持旧版网址格式:

"jdbc:firebirdsql:host[/port]:<database>"

Then, the correct URL should be: 然后,正确的URL应该是:

"jdbc:firebirdsql://localhost:3050/C:/firebird/database/EMPLOYEE.FDB"

Looking at the documentation on this site: http://www.firebirdsql.org/file/documentation/drivers_documentation/java/faq.html , item 3.1 查看本网站上的文档: http//www.firebirdsql.org/file/documentation/drivers_documentation/java/faq.html ,第3.1项

It seems that after the [port], you must have an slash "/" or double slash "//" in case you would connect on a linux server. 似乎在[port]之后,你必须有一个斜杠“/”或双斜杠“//”以防你在linux服务器上连接。

Your URL is most likely broken for this driver. 您的网址很可能因此驱动程序而中断。

Attach actual source to the jar and set a breakpoint in FBDataSource.getConnection(...) and see what values are actually present when the connection is attempted made. 将实际源附加到jar并在FBDataSource.getConnection(...)中设置断点,并查看尝试连接时实际存在的值。

Are you absolutely certain that the combination of a hostname with port agrees with a path to the FDB-file? 您是否完全确定主机名与端口的组合是否与FDB文件的路径一致?

To connect to the database located on remote machine or cloud (linux) then use following link. 要连接到位于远程计算机或云(linux)上的数据库,请使用以下链接。

jdbc:firebirdsql:34.212.208.251/3050:/opt/app/db/sample_training.fdb JDBC:firebirdsql:34.212.208.251/3050:/opt/app/db/sample_training.fdb

You should try this one. 你应该尝试这个。 It works for me on Windows. 它适用于Windows。

jdbc:firebirdsql://localhost:3050/C:\firebird\database\EMPLOYEE.FDB

Also make sure you added an exception for port 3050 to the Firewall. 还要确保将端口3050的例外添加到防火墙。

Connection string example for Apache Tomcat properties.xml with specified IP, port, data base alias and encoding: Apache Tomcat properties.xml的连接字符串示例,指定 IP、端口、数据库别名和编码:

<entry key="db.url">jdbc:firebirdsql:127.0.0.1/2222:my-db-alias?lc_ctype=WIN1251</entry>

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM