Get an error when connecting to Firebird database

2.4k Views Asked by At

Springboot: pom.xml org.firebirdsql.jdbc jaybird 4.0.0.java8

application.properties

spring.datasource.url=jdbc:firebirdsql://SERVER:3050/D:\company\DbPro\Data\file.fdb
spring.datasource.driverClassName=org.firebirdsql.jdbc.FBDriver

I get an error when querying the database:

Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is java.sql.SQLException: I/O error during "CreateFile (open)" operation for file "D:companyDbProDatafile.fdb"; Error while trying to open file; [SQLState:08001, ISC error code:335544344]

What's wrong?

1

There are 1 best solutions below

6
Mark Rotteveel On

As shown in the error message, Firebird tries to connect to a database D:companyDbProDatafile.fdb, which doesn't exist (or is otherwise inaccessible).

The reason your path is incorrect, is that \ denotes an escape in a properties file. As documented on Properties.load:

  • The method does not treat a backslash character, \, before a non-valid escape character as an error; the backslash is silently dropped. For example, in a Java string the sequence "\z" would cause a compile time error. In contrast, this method silently drops the backslash. Therefore, this method treats the two character sequence "\b" as equivalent to the single character 'b'.

To fix this, make sure to double back-slashes, or use the forward slash instead. So use:

spring.datasource.url=jdbc:firebirdsql://SERVER:3050/D:\\company\\DbPro\\Data\\file.fdb

or

spring.datasource.url=jdbc:firebirdsql://SERVER:3050/D:/company/DbPro/Data/file.fdb

Alternatively, instead of specifying a path to your database, configure an alias in databases.conf (Firebird 3 and higher) or aliases.conf (Firebird 2.5 and lower) and specify the alias in your connection string instead of the path.