Revision 11971 trunk/examples/exaLoadLayer/src/org/gvsig/example/postgis/LoadLayer.java
LoadLayer.java | ||
---|---|---|
20 | 20 |
import com.iver.cit.gvsig.fmap.ViewPort; |
21 | 21 |
import com.iver.cit.gvsig.fmap.core.ICanReproject; |
22 | 22 |
import com.iver.cit.gvsig.fmap.crs.CRSFactory; |
23 |
import com.iver.cit.gvsig.fmap.drivers.ConnectionFactory; |
|
24 |
import com.iver.cit.gvsig.fmap.drivers.ConnectionJDBC; |
|
25 |
import com.iver.cit.gvsig.fmap.drivers.DBException; |
|
23 | 26 |
import com.iver.cit.gvsig.fmap.drivers.DBLayerDefinition; |
24 |
import com.iver.cit.gvsig.fmap.drivers.VectorialJDBCDriver; |
|
27 |
import com.iver.cit.gvsig.fmap.drivers.IConnection; |
|
28 |
import com.iver.cit.gvsig.fmap.drivers.IVectorialJDBCDriver; |
|
25 | 29 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
26 | 30 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
27 | 31 |
import com.iver.cit.gvsig.fmap.layers.LayerFactory; |
... | ... | |
43 | 47 |
String pwd = "aquilina"; |
44 | 48 |
String layerName = actionCommand; |
45 | 49 |
String tableName = actionCommand; |
46 |
Connection conn; |
|
50 |
IConnection conn;
|
|
47 | 51 |
try { |
48 |
conn = DriverManager.getConnection(dbURL, user, pwd);
|
|
49 |
conn.setAutoCommit(false);
|
|
52 |
conn = ConnectionFactory.createConnection(dbURL, user, pwd);
|
|
53 |
((ConnectionJDBC)conn).getConnection().setAutoCommit(false);
|
|
50 | 54 |
|
51 | 55 |
String fidField = "gid"; // BE CAREFUL => MAY BE NOT!!! |
52 | 56 |
String geomField = "the_geom"; // BE CAREFUL => MAY BE NOT!!! => You should read table GEOMETRY_COLUMNS. |
53 | 57 |
// See PostGIS help. |
54 | 58 |
|
55 | 59 |
// To obtain the fields, make a connection and get them. |
56 |
Statement st = conn.createStatement();
|
|
60 |
Statement st = ((ConnectionJDBC)conn).getConnection().createStatement();
|
|
57 | 61 |
ResultSet rs = st.executeQuery("select * from " + tableName + " LIMIT 1"); |
58 | 62 |
ResultSetMetaData rsmd = rs.getMetaData(); |
59 | 63 |
String[] fields = new String[rsmd.getColumnCount()-1]; // We don't want to include the_geom field |
... | ... | |
71 | 75 |
|
72 | 76 |
String whereClause = ""; |
73 | 77 |
|
74 |
VectorialJDBCDriver driver = (VectorialJDBCDriver) LayerFactory.getDM()
|
|
78 |
IVectorialJDBCDriver driver = (IVectorialJDBCDriver) LayerFactory.getDM()
|
|
75 | 79 |
.getDriver("PostGIS JDBC Driver"); |
76 | 80 |
|
77 | 81 |
// Here you can set the workingArea |
... | ... | |
121 | 125 |
} catch (DriverLoadException e) { |
122 | 126 |
// TODO Auto-generated catch block |
123 | 127 |
e.printStackTrace(); |
128 |
} catch (DBException e) { |
|
129 |
// TODO Auto-generated catch block |
|
130 |
e.printStackTrace(); |
|
124 | 131 |
} |
125 | 132 |
|
126 | 133 |
|
Also available in: Unified diff