首页 / 浏览问题 / 组件GIS / 问题详情
求帮看下存入数据的代码有问题没,谢谢
185EXP 2018年01月23日
String LINE_NAME = null;
        int TRAFFIC_TYPE =0;
        long LINE_ID = 0;
        String LINE_NO = null;
        int IS_UP_DOWN = 0;
        long CITY_ID=0;
        Geometry geometry = recordset.getGeometry();
        while(result.next()){
            LINE_NAME = result.getString("LINE_NAME");
            TRAFFIC_TYPE = result.getInt("TRAFFIC_TYPE");
            LINE_ID = result.getLong("LINE_ID");
            LINE_NO = result.getString("LINE_NO");
            IS_UP_DOWN = result.getInt("IS_UP_DOWN");
            CITY_ID = result.getLong("CITY_ID");
            
            for(int i =0;i<listAll.size();i++){
                if(LINE_NO.equals((String) listAll.get(i).get(0)) & IS_UP_DOWN==(int) listAll.get(i).get(1) & CITY_ID==(Long) listAll.get(i).get(2)){
                    System.out.println(LINE_NO.equals((String) listAll.get(i).get(0)) & IS_UP_DOWN==(int) listAll.get(i).get(1) & CITY_ID==(Long) listAll.get(i).get(2));
                    System.out.println(LINE_NO+","+IS_UP_DOWN+","+CITY_ID+"-----------");
                    java.util.Map map = new java.util.HashMap();
                     map.put("LINE_NAME", LINE_NAME);
                     map.put("TRAFFIC_TYPE", TRAFFIC_TYPE);
                     map.put("LINE_ID", LINE_ID);
                     recordset.addNew(geometry, map);
                     recordset.update();
                }
            }
        }
问题关闭原因: 已解决

1个回答

代码里的对象不清晰Geometry geometry = recordset.getGeometry();这个recordset到底是记录集集合还是某一条记录?recordset.addNew(geometry, map);如果追加对象,那么这个recordset必须是数据集的记录集集合,geometry是哪一个对象?while循环里没有执行recordset的游标移动。建议在联机帮助文档里看看Recordset和Recordset.BatchEditor类,里面有使用的示例代码。
1,565EXP 2018年01月23日

上面那只是一部分的代码,下面是全部的代码及输出结果

package LinePointTransform;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import com.mchange.v2.c3p0.ComboPooledDataSource;
import com.supermap.data.CursorType;
import com.supermap.data.DatasetVector;
import com.supermap.data.Datasource;
import com.supermap.data.DatasourceConnectionInfo;
import com.supermap.data.EngineType;
import com.supermap.data.Geometry;
import com.supermap.data.Recordset;
import com.supermap.data.Workspace;

/*
 * 轨迹点转线之后没有LINE_NAME、TRAFFIC_TYPE、LINE_ID等字段
 * 更新缺失字段
 */
public class UpdateProperty {

    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        // TODO Auto-generated method stub
        Workspace workspace = new Workspace();
        System.out.println(workspace.getVersion());
        /*DatasourceConnectionInfo datasourceConnectionInfo = new DatasourceConnectionInfo("D:/0000000事例数据/ZhengZhouPaFlow.udd",
                                         "zhengzhou", "");*/
        DatasourceConnectionInfo datasourceConnectionInfo = new DatasourceConnectionInfo();
        datasourceConnectionInfo.setEngineType(EngineType.ORACLEPLUS);
        datasourceConnectionInfo.setServer("TrafficTransferAnalyst");
        datasourceConnectionInfo.setDatabase("TrafficTransferAnalyst");
        datasourceConnectionInfo.setUser("TrafficTransferAnalyst");
        datasourceConnectionInfo.setPassword("TrafficTransferAnalyst");
        datasourceConnectionInfo.setAlias("ORACLE");
        Datasource targetDatasource = workspace.getDatasources().open(
                datasourceConnectionInfo);
        DatasetVector TM_SM_STATION_METRO_INFO = (DatasetVector) targetDatasource.
                getDatasets().get("TM_SM_LINE_GIS_INFO");
        Recordset recordset = TM_SM_STATION_METRO_INFO.getRecordset(false, CursorType.DYNAMIC);
        //获取工作空间中线路的数据
        String line_no = null;
        int is_up_down = 0;
        long city_id=0;
        ArrayList<ArrayList> listAll = new ArrayList<ArrayList>();
        for(int i = 0; i<recordset.getRecordCount();i++){
            ArrayList list = new ArrayList();
            line_no = recordset.getString("LINE_NO");
            is_up_down = recordset.getInt32("IS_UP_DOWN");
            city_id = recordset.getInt32("CITY_ID");
            list.add(line_no);
            list.add(is_up_down);
            list.add(city_id);
            listAll.add(list);
            recordset.moveNext();
        }
        //从数据库中取出来的数据
        Class.forName("oracle.jdbc.driver.OracleDriver");
        ComboPooledDataSource dataSource=new ComboPooledDataSource("oracle");
        Connection conn=dataSource.getConnection();
        String sql ="select  a.line_name,a.line_id,a.traffic_type,b.city_id,b.is_up_down,b.line_no from tm_sm_line_gis_info a ,baoding_TM_LINE_POINT_PRE b where a.line_no=b.line_no and a.is_up_down = b.is_up_down";
        PreparedStatement ps = conn.prepareStatement(sql);
        ResultSet result=ps.executeQuery();
        String LINE_NAME = null;
        int TRAFFIC_TYPE =0;
        long LINE_ID = 0;
        String LINE_NO = null;
        int IS_UP_DOWN = 0;
        long CITY_ID=0;
        Geometry geometry = recordset.getGeometry();
        while(result.next()){
            LINE_NAME = result.getString("LINE_NAME");
            TRAFFIC_TYPE = result.getInt("TRAFFIC_TYPE");
            LINE_ID = result.getLong("LINE_ID");
            LINE_NO = result.getString("LINE_NO");
            IS_UP_DOWN = result.getInt("IS_UP_DOWN");
            CITY_ID = result.getLong("CITY_ID");
            
            for(int i =0;i<listAll.size();i++){
                if(LINE_NO.equals((String) listAll.get(i).get(0)) & IS_UP_DOWN==(int) listAll.get(i).get(1) & CITY_ID==(Long) listAll.get(i).get(2)){
                    System.out.println(LINE_NO.equals((String) listAll.get(i).get(0)) & IS_UP_DOWN==(int) listAll.get(i).get(1) & CITY_ID==(Long) listAll.get(i).get(2));
                    System.out.println(LINE_NO+","+IS_UP_DOWN+","+CITY_ID+"-----------");
                    java.util.Map map = new java.util.HashMap();
                     map.put("LINE_NAME", LINE_NAME);
                     map.put("TRAFFIC_TYPE", TRAFFIC_TYPE);
                     map.put("LINE_ID", LINE_ID);
                     recordset.addNew(geometry, map);
                     recordset.update();
                }
            }
        }
        System.out.println("完成");
        ps.close();
        conn.close();
        datasourceConnectionInfo.dispose();
        workspace.close();
        workspace.dispose();
    }

}

recordset获取的是线性的记录集集合

需要指定到某一条recordset记录才能获取该记录的字段信息

在listAll中已经获取了字段的信息,要不然在if做判断的时候也不会输出true啊,这是线性数据集的信息,recordset中只获取了其中的line_no、is_up_down、city_id字段,line_nane 、traffic_type、line_id的字段没有数据,我就没有获取,现在代码做的就是根据recordset获取的数据和在数据库中获取的数据做下判断,如果是正确的话,把数据库中查询出来的对应的数据插入到数据集中就行了,现在是数据能获取出来,判断也是对的,就是没有插入进去,之前问过李熙,他给我说用addNew方法,但是这个地方好像不合适,set+字段类型的方法和setFieldValue方法也尝试了 都没有插入进去,在这个插入的地方我有点懵了.....

...