1

I am trying to configure and use embedded Firebird with log4j. Essentially I want to log my entries to a DB table (Firebird). I am unable to do so with "Connection Refused" error complete call stack pasted below.

There was one possibility for this error that was a mismatched 32 vs 64 bit libraries being used / invoked, but if I write a simple java program and use Jaybird-full-2.2.9.jar I am able to connect and get data. It seems to be a problem when using log4j's property file.

Any help regarding this is appreciated.

    log4j:ERROR Failed to excute sql
org.firebirdsql.jdbc.FBSQLException: GDS Exception. 335544721. Unable to complete network request to host "localhost".
    at org.firebirdsql.jdbc.FBDataSource.getConnection(FBDataSource.java:120)
    at org.firebirdsql.jdbc.AbstractDriver.connect(AbstractDriver.java:138)
    at java.sql.DriverManager.getConnection(DriverManager.java:664)
    at java.sql.DriverManager.getConnection(DriverManager.java:247)
    at org.apache.log4j.jdbc.JDBCAppender.getConnection(JDBCAppender.java:251)
    at org.apache.log4j.jdbc.JDBCAppender.execute(JDBCAppender.java:215)
    at org.apache.log4j.jdbc.JDBCAppender.flushBuffer(JDBCAppender.java:289)
    at org.apache.log4j.jdbc.JDBCAppender.append(JDBCAppender.java:186)
    at org.apache.log4j.AppenderSkeleton.doAppend(AppenderSkeleton.java:251)
    at org.apache.log4j.helpers.AppenderAttachableImpl.appendLoopOnAppenders(AppenderAttachableImpl.java:66)
    at org.apache.log4j.Category.callAppenders(Category.java:206)
    at org.apache.log4j.Category.forcedLog(Category.java:391)
    at org.apache.log4j.Category.info(Category.java:666)
    at com.xip.engines.Log4jAuditLoggerImpl.insert_AuitdLog(Log4jAuditLoggerImpl.java:20)
    at com.xip.engines.Log4jAuditLoggerImpl.main(Log4jAuditLoggerImpl.java:40)
Caused by: org.firebirdsql.gds.GDSException: Unable to complete network request to host "localhost".
    at org.firebirdsql.gds.impl.wire.AbstractJavaGDSImpl.connect(AbstractJavaGDSImpl.java:1876)
    at org.firebirdsql.gds.impl.wire.AbstractJavaGDSImpl.internalAttachDatabase(AbstractJavaGDSImpl.java:431)
    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)
    ... 14 more
Caused by: java.net.ConnectException: Connection refused: connect
    at java.net.DualStackPlainSocketImpl.connect0(Native Method)
    at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:345)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    at java.net.Socket.connect(Socket.java:589)
    at org.firebirdsql.gds.impl.wire.AbstractJavaGDSImpl.openSocket(AbstractJavaGDSImpl.java:1969)
    at org.firebirdsql.gds.impl.wire.AbstractJavaGDSImpl.connect(AbstractJavaGDSImpl.java:1852)
    ... 20 more

Here is the log4j properties file I use.

# Define the root logger with file appender
log4j.rootLogger = ALL, DB
#log4j.category.org.firebirdsql=ALL, stdout
# Define the file appender
log4j.appender.DB=org.apache.log4j.jdbc.JDBCAppender
#log4j.appender.DB.URL=jdbc\:firebirdsql\://localhost\:3050/C\:\\xxxx\\xxxxx.FDB
log4j.appender.DB.URL=jdbc\:firebirdsql\://embedded\:C\:\\C\:\\xxxx\\xxxxx.FDB
#log4j.appender.DB.URL=jdbc\:firebirdsql\://local\:C\:\\C\:\\xxxx\\xxxxx.FDB
# Set Database Driver
log4j.appender.DB.driver=org.firebirdsql.jdbc.FBDriver
# Set database user name and password
log4j.appender.DB.user=SYSDBA
#log4j.appender.DB.password=masterkey
log4j.appender.DB.password=
# Set the SQL statement to be executed.
log4j.appender.DB.sql=INSERT INTO AUDITLOG VALUES (null,'%d{yyyy-MM-dd HH:mm:ss}', '%m', '%X{Type}', '%X{UserName}')
# Define the xml layout for file appender
log4j.appender.DB.layout=org.apache.log4j.PatternLayout
Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Maruthi
  • 33
  • 1
  • 6
  • The error indicates that you're not using the Firebird embedded protocol, but the normal (java) protocol to connect to a Firebird server. Please show the JDBC URL you use to connect (and the rest of the log4j JDBC appender config). Also see [JDBC URL Format, Embedded server](http://www.firebirdsql.org/file/documentation/drivers_documentation/java/2.2.10/release_notes.html#embedded-server) in the Jaybird release notes. – Mark Rotteveel Apr 13 '16 at 19:22
  • Hello Mark, Thank you for your response. I have updated my question with Log4j properties file content. – Maruthi Apr 14 '16 at 11:19

1 Answers1

1

You are using an incorrect URL, the URL format for embedded is:

jdbc:firebirdsql:embedded:<database>

The url shown in your config (after removal of the escapes of the colon) is:

jdbc:firebirdsql://embedded:C:\\C\:\\xxxx\\xxxxx.FDB

Removing // should fix this (the same applies to the jdbc:firebirdsql:local URL shown commented out).

URLs with jdbc:firebirdsql://.... are handled by the pure java network protocol implementation. Given the config I would have expected a different error (because parsing the URL would fail), but I assume this might be a result of trying different configurations.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197