Revision 1755 branches/FMap_SLD/libraries/libFMap/src/com/iver/cit/gvsig/fmap/drivers/jdbc/postgis/testPostGis.java
testPostGis.java | ||
---|---|---|
49 | 49 |
import java.sql.Statement; |
50 | 50 |
import java.util.Enumeration; |
51 | 51 |
|
52 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
|
53 |
import com.iver.cit.gvsig.fmap.drivers.WKBParser; |
|
52 | 54 |
|
55 |
|
|
53 | 56 |
/** |
54 | 57 |
* @author FJP |
55 | 58 |
* |
... | ... | |
71 | 74 |
String dbuser = "postgres"; |
72 | 75 |
String dbpass = "aquilina"; |
73 | 76 |
|
74 |
String dbtable = "jdbc_test";
|
|
77 |
String dbtable = "vias";
|
|
75 | 78 |
|
76 | 79 |
java.sql.Connection conn; |
77 | 80 |
try |
... | ... | |
101 | 104 |
/* |
102 | 105 |
* Create a statement and execute a select query. |
103 | 106 |
*/ |
104 |
String strSQL = "select ASBINARY(the_geom) as geom from vias";
|
|
107 |
String strSQL = "select ASBINARY(the_geom) as geom from " + dbtable;
|
|
105 | 108 |
/* String strSQL = "SELECT gid, rd_3, rd_5, rd_6, rd_10, rd_11, rd_12, rd_13, rd_14,"; |
106 | 109 |
strSQL = strSQL + " rd_15, rd_16, kilometers, cost, metros, AsText(force_2d(the_geom)) FROM vias"; |
107 | 110 |
strSQL = strSQL + " WHERE TRUE"; |
108 | 111 |
*/ |
109 | 112 |
// PreparedStatement s = conn.prepareStatement(strSQL); |
110 | 113 |
long t1 = System.currentTimeMillis(); |
111 |
Statement s = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); |
|
112 |
s.setFetchSize(20000); |
|
113 |
ResultSet r = s.executeQuery(strSQL); |
|
114 |
Statement s = conn.createStatement(); |
|
115 |
// s.execute("begin"); |
|
116 |
|
|
117 |
// Statement s = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); |
|
118 |
s.setFetchSize(2000); |
|
119 |
s.execute("declare wkb_cursor binary cursor for " + strSQL); |
|
120 |
ResultSet r = s.executeQuery("fetch forward all in wkb_cursor"); |
|
121 |
|
|
122 |
// ResultSet r = s.executeQuery(strSQL); |
|
114 | 123 |
long t2 = System.currentTimeMillis(); |
115 | 124 |
|
116 | 125 |
System.out.println("Tiempo de consulta:" + (t2 - t1) + " milisegundos"); |
117 | 126 |
t1 = System.currentTimeMillis(); |
127 |
WKBParser parser = new WKBParser(); |
|
118 | 128 |
while( r.next() ) |
119 | 129 |
{ |
120 | 130 |
/* |
121 | 131 |
* Retrieve the geometry as an object then cast it to the geometry type. |
122 | 132 |
* Print things out. |
123 | 133 |
*/ |
124 |
Object obj = r.getObject(1); |
|
125 |
// InputStream inS = r.getAsciiStream(1); |
|
134 |
// Object obj = r.getObject(1); |
|
135 |
byte[] arrayByte = r.getBytes(1); |
|
136 |
IGeometry gp = parser.parse(arrayByte); |
|
126 | 137 |
// String strAux = r.getString(1); |
127 | 138 |
// int id = r.getInt(2); |
128 | 139 |
// System.out.println("Row " + id + ":"); |
Also available in: Unified diff