angel208 angel208 - 3 months ago 12
Java Question

Using Jaybird to connect to a Firebird database located in a computer in a local network

I'm creating a java application that connects to a Firebird database and retrieve some data. The program is done, and it runs well in my computer. The problem is that, in the computer I need to run the application, the database is in another computer in the local network and I have no idea of which path should I put into the connection string of jaybird to get it running. Let me explain a bit:

I need to run my application in a computer X, but the actual database is not in a drive in the computer, but in a computer in the local network. Something like this (this is an example, and its reproduced at my home, not at the actual site I need to get it to work):

enter image description here

So the path that it gives me for the database is something like:

enter image description here

I know that if my database is in my drive ( for example, in C:\Users\john\Desktop ), my connection to the database using Jaybird should be something like this:

static final String FB_DB_URL = "jdbc:firebirdsql://localhost:3050/C:\\Users\\john\\Desktop\\TEST1.FDB";

FB_connection = DriverManager.getConnection( FB_DB_URL , FB_USER , FB_PASS);


Actually, that is how I managed to make it work in my computer. But in this case I have no clue of how should the path be. I tried something like:

static final String FB_DB_URL = "jdbc:firebirdsql://192.168.0.101:3050/\\\\DESKTOP-1UFA09I\\Documents\\TEST1.FDB";


With ‘192.168.0.101’ being the ipv4 address of the computer where the database is. But this gave me an exception saying that the application was unable to find the database. I think this is the closest I was to find the solution, but I had no luck.
Some extra information:


  • Both computers had the firewall off, and could send ping to each other, so they are, in fact, connected.

  • I'm using Firebird 2.5 and jaybird 2.2.1.

  • I also tried the following with no luck:

    static final String FB_DB_URL = "jdbc:firebirdsql://192.168.0.101:3050/C:\\users\\john2\\Documents\\TEST1.FDB";

  • The folder is shared (or at least, that’s what I think) because I can get access to it via windows, and the database file gives read/write permissions to everyone.

  • I'm sure that Firebird is running in both PCs.



Any help in the matter would be greatly appreciated. I'm sure the problem is in the path, because, as I said, the application works well in with the database in my computer. Also, if you could give me a solution that doesn’t require the IP of the computer where the DB is stored that would be awesome, but I think I can get that information anyways.

EDIT

For documenting purposes the solution to the problem was the following:

the right way of making the path to the database is:

"jdbc:firebirdsql://192.168.0.101:3050/C:\\folder1\\folder2\\TEST1.FDB";


the exception occurred because, apparently, jaybird has some permission issues with the
users
folder in the server. As my DB was located in the
documents
folder, it was causing some problems when jaybird tried to get access to it. the solution is to move the DB to another folder in
C://

Answer

To connect to a remote database you need to know the following things:

  • The hostname or IP address of the Firebird server
  • The port number of the Firebird server (default 3050)
  • User name and password
  • Alias of the database or the full path of the database

You seem to have the first three items covered, so the problem is with the fourth. You think the database is located in C:\users\john2\Documents\TEST1.FDB. If that is the case, then the JDBC url is:

jdbc:firebirdsql://192.168.0.101:3050/C:\\users\\john2\\Documents\\TEST1.FDB

However, the user running the Firebird server process by default has no access to user folders for security reasons.

I suggest that you move the database to a location outside of the user folder, and make sure the account running the Firebird server service has read and write access (NETWORK SERVICE or LOCAL SYSTEM, I forgot which and I currently don't have access to Windows machine) .

Other notes:

  • Locations of a Firebird database should not be shared, because accessing a database remotely should be done through a Firebird server
  • You should really update to Jaybird 2.2.11; 2.2.1 is almost 4 years old and a lot has been fixed since
  • If you are really using Firebird 2.5(.0), then upgrade to 2.5.6, or consider upgrading to 3.0
Comments