2016-05-09 20 views
0

我已經使用eclipse創建了一個項目,並將postgis-jdbc-2.1.7.jar,postgresql-9.4.1208.jre6.jar添加到我的類路徑。嘗試向我的postgis連接添加幾何類型時出錯

然後我試着從postgis文檔see example的例子來連接到數據庫。

以下各行產生一個錯誤:

/* 
* Add the geometry types to the connection. Note that you 
* must cast the connection to the pgsql-specific connection 
* implementation before calling the addDataType() method. 
*/ 
    ((org.postgresql.PGConnection)conn).addDataType("geometry",Class.forName("org.postgis.PGgeometry")); 
    ((org.postgresql.PGConnection)conn).addDataType("box3d",Class.forName("org.postgis.PGbox3d")); 

誤差如下:

在類型連接的方法addDataType不適用於

有其他人面臨的參數

同樣的錯誤?

任何想法?

回答

1

這是一個運行時錯誤嗎?也許Class.forName()返回null。嘗試通過用「org.postgis.PGgeometry.class」替換對「Class.forName()」的調用來對該類進行靜態引用,如果類路徑處於關閉狀態,這將在編譯時失敗,而不是運行時。

+1

這實在是一個評論,而不是一個答案。有了更多的代表,[你將能夠發表評論](// stackoverflow.com/privileges/comment)。我將這個帖子標記爲刪除。 – Mat

相關問題