String server = "menglikunm";
int instance = 5151;
String database = "ora";
String user = "suzhou";
String password = "suzhou";
public Long addPointObject(long x, long y, String tabname) throws Exception { SeLayer insertLayer = null; SeConnection conn = null; Long intsertRowID = null; try { conn = new SeConnection(server, instance, database, user, password); Vector layerList = conn.getLayers(); for (int index = 0; index < layerList.size(); index++) { SeLayer layer = (SeLayer) layerList.elementAt(index); System.out.println(layer.getName()); if ( layer.getName().equalsIgnoreCase(tabname)) { insertLayer = layer; break; } } } catch (SeException e) { // e.printStackTrace(); throw e; } // 开始插入数据 if (insertLayer == null) { throw new Exception("找不到空间表:" + tabname); } try { conn.startTransaction(); String[] cols = new String[1]; //cols[0] = insertLayer.getSpatialColumn(); cols[0]="SHAPE"; System.out.println(cols[0]); SeInsert insert = new SeInsert(conn); System.out.println(insertLayer.getName()); insert.intoTable(insertLayer.getName(), cols);//运行到这里时出现错误! insert.setWriteMode(true); SeCoordinateReference coordref = (SeCoordinateReference) insertLayer .getCoordRef(); SeShape shape = new SeShape(coordref);
int numPts = 1; SDEPoint[] ptArray = new SDEPoint[numPts]; ptArray[0] = new SDEPoint(x, y); shape.generatePoint(numPts, ptArray); SeRow row = insert.getRowToSet(); row.setShape(0, shape); insert.execute(); intsertRowID = new Long(insert.lastInsertedRowId().longValue()); insert.close(); conn.commitTransaction(); conn.close(); } catch (Exception ex) { ex.printStackTrace (); try { conn.rollbackTransaction(); conn.close(); } catch (Exception ex2) { } throw ex; } return intsertRowID; }
Powered by: BlogJava Copyright © Kevin Meng