2016-04-13 90 views
1

我想配置和使用嵌入式火鳥與log4j。基本上我想將我的條目記錄到數據庫表(Firebird)。我無法完成下面粘貼的「連接被拒絕」錯誤完整的調用堆棧。嵌入式火鳥和Log4j配置

這種錯誤有一種可能性,即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 
+0

錯誤表明您沒有使用Firebird嵌入式協議,而是使用正常(java)協議連接到Firebird服務器。請顯示您用來連接的JDBC URL(以及log4j JDBC appender config的其餘部分)。另請參閱Jaybird發行說明中的​​[JDBC URL格式,嵌入式服務器](http://www.firebirdsql.org/file/documentation/drivers_documentation/java/2.2.10/release_notes.html#embedded-server)。 –

+0

Hello Mark,感謝您的回覆。我用Log4j屬性文件內容更新了我的問題。 – Maruthi

回答

1

您使用了不正確的URL,該URL format for embedded是:

jdbc:firebirdsql:embedded:<database> 

在你的配置(切除結腸的逃逸後)顯示的網址是:

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

刪除//應該修復此問題(同樣適用於顯示註釋的jdbc:firebirdsql:local URL)。

jdbc:firebirdsql://....的URL由純java網絡協議實現處理。鑑於配置,我會期望一個不同的錯誤(因爲解析URL會失敗),但我認爲這可能是嘗試不同配置的結果。

+0

完美!這解決了我的問題。事實上,這是一個現場。非常感謝 – Maruthi