postgresql數據庫中與jdbc進行通訊的格式有二進制方式和文本方式。二進制方式這是針對某些數據類型而言的。那麼若是想只經過文本方式來進行通訊,怎麼解決了。下面提供了一段創建鏈接的方式,能夠禁止jdbc經過二進制與postgresql進行通訊。java
private void disableBinary(Properties info) { int[] disableType = {Oid.BYTEA, Oid.INT2, Oid.INT4, Oid.INT8, Oid.FLOAT4, Oid.FLOAT8, Oid.TIME, Oid.DATE, Oid.TIMETZ, Oid.TIMESTAMP, Oid.TIMESTAMPTZ, Oid.INT2_ARRAY, Oid.INT4_ARRAY, Oid.INT8_ARRAY, Oid.FLOAT4_ARRAY, Oid.FLOAT8_ARRAY, Oid.VARCHAR_ARRAY, Oid.TEXT_ARRAY, Oid.POINT, Oid.BOX, Oid.UUID}; String dstring = null; int i = 0; for (i = 0; i < disableType.length; ++i) { if (i > 0) dstring = dstring + ","; if (dstring == null) { dstring = String.valueOf(disableType[i]); } else { dstring = dstring + String.valueOf(disableType[i]); } } PGProperty.BINARY_TRANSFER_DISABLE.set(info, dstring); } public void SelectUser() { Connection conn = null; String url = "jdbc:postgresql://172.30.12.10:1999/pgbench"; String username = "db_user"; String password = "0000"; try { Class.forName("org.postgresql.Driver").newInstance(); java.util.Properties info = new java.util.Properties(); info.setProperty("user", username); info.setProperty("password", password); disableBinary(info); conn = DriverManager.getConnection(url, info);
在上面代碼中disableBinary函數禁止了全部jdbc中指定二進制進行通訊的數據類型。這樣創建的鏈接就只會經過文本進行通訊了。sql
上面的disableBinary函數中的代碼也能夠使用一句代碼來完成:PGProperty.BINARY_TRANSFER.set(info, false)。這句代碼就能夠把jdbc中全部的數據類型都指定爲使用文本進行通訊。數據庫