首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Geotools 13 -在linux中写入MySQL时出错

Geotools 13 -在linux中写入MySQL时出错
EN

Stack Overflow用户
提问于 2015-04-23 06:02:37
回答 1查看 107关注 0票数 1

注意:运行geotools 13.0。

我有一个创建点形状的应用程序。然后,我的应用程序将这些特性写入shapefile,然后写入MySQL。

当我在Windows下运行代码时,一切都运行得很完美:数据被正确地存储在MySQL中,我可以毫不费力地使用它。

当我在Linux下运行代码时,shapefile被创建了,但是数据不是用MySQL写的,并且抛出了以下异常:

代码语言:javascript
复制
WARNING: class org.geotools.filter.function.Collection_NearestFunction has name conflict betwee 'null' and 'Collection_Nearest'
Exception in thread "main" java.lang.NoSuchFieldError: LINEARIZATION_TOLERANCE
at org.geotools.jdbc.JDBCFeatureReader.init(JDBCFeatureReader.java:211)
at org.geotools.jdbc.JDBCFeatureReader.<init>(JDBCFeatureReader.java:137)
at org.geotools.jdbc.JDBCInsertFeatureWriter.<init>(JDBCInsertFeatureWriter.java:43)
at org.geotools.jdbc.JDBCFeatureStore.getWriterInternal(JDBCFeatureStore.java:280)
at org.geotools.data.store.ContentFeatureStore.getWriter(ContentFeatureStore.java:151)
at org.geotools.data.store.ContentFeatureStore.getWriter(ContentFeatureStore.java:122)
at org.geotools.data.store.ContentFeatureStore.getWriterAppend(ContentFeatureStore.java:263)
at org.geotools.data.store.ContentFeatureStore.addFeatures(ContentFeatureStore.java:242)
at com.technip.projects.gis.GISGenerator.writeShapesMySQL(GISGenerator.java:763)
at com.technip.projects.gis.GISGenerator.generatePlatforms(GISGenerator.java:416)
at com.technip.projects.gis.GISGenerator.createShapefiles(GISGenerator.java:249)
at Machine.run(Machine.java:739)
at Machine.main(Machine.java:329)

我的代码:

代码语言:javascript
复制
private void writeShapesMySQL(List<SimpleFeature> features) throws IOException {
    SimpleFeatureType TYPE = null;

    if (!features.isEmpty()) {
        TYPE = features.get(0).getType();

        // Drop the table if exists
        try (Connection con = conf.requestConnection("gis")) {
            con.prepareCall("DROP TABLE IF EXISTS " + TYPE.getTypeName() + ";").execute();
        } catch (Exception e) {}
        if (factory == null) {
            initMySQLStore();
        }

        SimpleFeatureCollection collection = new ListFeatureCollection(TYPE, features);

        gisDS.createSchema(TYPE);

        Transaction transaction = new DefaultTransaction("create");
        String      typeName    = null;

        for (String s : gisDS.getTypeNames()) {
            if (s.equalsIgnoreCase(TYPE.getTypeName())) {
                typeName = s;
                break;
            }
        }
        if (typeName == null) {
            log.error("Cannot find the type " + TYPE.getTypeName() + " in the known types: " + String.valueOf(gisDS.getTypeNames()));
            throw new IOException("Cannot find type " + TYPE.getTypeName() + " -- in other words, developer sucks.");
        }

        SimpleFeatureSource featureSource = gisDS.getFeatureSource(typeName);

        // System.out.println("SHAPE:"+SHAPE_TYPE);
        if (featureSource instanceof SimpleFeatureStore) {
            SimpleFeatureStore featureStore = (SimpleFeatureStore) featureSource;

            featureStore.setTransaction(transaction);
            try {
                log.info("Adding " + collection.size() + " features into " + TYPE.getTypeName() + " table.");
                featureStore.addFeatures(collection);
                transaction.commit();
            } catch (Exception problem) {
                log.error("Cannot create shapes in MySQL for " + TYPE.getTypeName(), problem);
                transaction.rollback();
            } finally {
                transaction.close();
            }
        }
    } else {
        log.warn("Passed empty list to create GIS database.");
    }
}

 private void initMySQLStore() throws IOException {
    factory = new MySQLDataStoreFactory();

    Map conMap = new HashMap();

    conMap.put("dbtype", "mysql");
    conMap.put("host", conf.getDbserver());
    conMap.put("port", "3306");
    conMap.put("database", "gis");
    conMap.put("user", conf.getDbuser());
    conMap.put("passwd", conf.getDbpass());

    gisDS = factory.createDataStore(conMap);

    Map<Class<?>, Integer> classMappings = gisDS.getClassToSqlTypeMappings();

    classMappings.put(String.class, new Integer(Types.LONGVARCHAR));
}

我的第一个提示是,MySQL在Linux中区分大小写,但在Windows中不区分大小写。因此,我检查了在Linux和Windows中创建的表,没有一个表具有这样的名称(LINEARIZATION_TOLERANCE)字段。

有什么提示吗?

谢谢,

胡安

--更新:问题解决--

事实证明,我在Linux机器上有一个旧的.jar,来自以前版本的geotools。移除所有旧的jars解决了这个问题。

EN

回答 1

Stack Overflow用户

发布于 2015-04-24 22:03:45

问题已解决:

事实证明,我在Linux机器上有一个旧的.jar,来自以前版本的geotools。移除所有旧的jars解决了这个问题。

忽略这一点,这是一个用户错误。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29809724

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档