1

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?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
  • Related, technically duplicate: [Java Properties backslash](https://stackoverflow.com/questions/5784895/java-properties-backslash) (I decided not to use my gold hammer to close, because I also provide a Firebird-specific alternative in my answer) – Mark Rotteveel Jun 10 '20 at 19:12

1 Answers1

1

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.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
  • @AndreyKonus If my answer solved your problem, then please accept the answer by clicking the checkmark. – Mark Rotteveel Jun 10 '20 at 19:24
  • `because the path is invalid`, well, *technically* this path is perfectly valid, but in practice it is so random that... run like hell!!! :-D But valid it is. – Arioch 'The Jun 11 '20 at 12:03
  • @Arioch'The It is questionable if the path `D:companyDbProDatafile.fdb` without a backslash after the driveletter is valid. – Mark Rotteveel Jun 11 '20 at 12:39
  • @MarkRotteveel if you do not override OS standards with you own ad hoc definition (and you did not say you do) then is is not questionable, it is valid path. File or folder "companyDbProDatafile.fdb" placed inside the current folder of drive D: – Arioch 'The Jun 11 '20 at 13:40
  • @Arioch'The Do you have a citation for that, because as far as I'm aware, that behaviour only exists in the command prompt and only for compatibility with DOS. – Mark Rotteveel Jun 11 '20 at 14:36
  • 1
    @MarkRotteveel it definitely is because of CP/M (not even DOS) legacy, but heritage is not synonimous to invalidity. First link in Microsoft Bing: "If a file name begins with only a disk designator but not the backslash after the colon, it is interpreted as a relative path to the current directory on the drive" - just one option listed among many other options of constructing valid filenames at https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file – Arioch 'The Jun 12 '20 at 20:14