嵌入式Firebird和Log4j配置

时间:2016-04-13 15:52:53

标签: java firebird jaybird firebird-embedded

我正在尝试使用log4j配置和使用嵌入式Firebird。基本上我想将我的条目记录到数据库表(Firebird)。我无法在下面粘贴“连接已拒绝”错误完成调用堆栈。

这个错误有一种可能性是使用/调用了不匹配的32位64位库,但如果我编写一个简单的java程序并使用Jaybird-full-2.2.9.jar,我就可以连接并获取数据。使用log4j的属性文件时似乎有问题。

对此有任何帮助表示赞赏。

    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

这是我使用的log4j属性文件。

# 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

1 个答案:

答案 0 :(得分:1)

您使用的网址不正确,URL format for embedded为:

jdbc:firebirdsql:embedded:<database>

配置中显示的网址(删除冒号转义后)为:

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

删除//应解决此问题(同样适用于已注明的jdbc:firebirdsql:local网址。)

具有jdbc:firebirdsql://....的URL由纯Java网络协议实现处理。鉴于配置我会期望一个不同的错误(因为解析URL会失败),但我认为这可能是尝试不同配置的结果。