Hello,
I use following code to modify existing features in MySQL database:
try {
Transaction transaction = new DefaultTransaction();
FeatureWriter<? extends FeatureType, ? extends Feature> fWriter = null;
//fWriter = mySQLDataStore.getFeatureWriter("streets",
transaction.AUTO_COMMIT);
fWriter = mySQLDataStore.getFeatureWriter("streets");
if (fWriter != null) {
while (fWriter.hasNext()) {
SimpleFeature feature = (SimpleFeature) fWriter.next();
String name = (String) (feature.getAttribute("name"));
if (name.trim().equals("some street name"))
feature.setAttribute("state", 1);
fWriter.write();
}
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
transaction.close();
fWriter.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
When i try to update feature attribute in database with fWriter.write(); i
get SQL exception:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error
in your SQL syntax; check the manual that corresponds to your MySQL server
version for the right syntax to use near '' at line 1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:532)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.Util.getInstance(Util.java:381)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1030)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3558)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3490)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1959)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2109)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2642)
at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1647)
at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1566)
at
org.apache.commons.dbcp.DelegatingStatement.executeUpdate(DelegatingStatement.java:228)
at
org.geotools.data.jdbc.JDBCTextFeatureWriter.doUpdate(JDBCTextFeatureWriter.java:425)
at
org.geotools.data.jdbc.JDBCFeatureWriter.write(JDBCFeatureWriter.java:197)
at
org.geotools.data.InProcessLockingManager$1.write(InProcessLockingManager.java:335)
Can someone help me about this, what i am doing wrong?
I tried same code with PostGIS and everything works fine.
Best regards.
--
View this message in context:
http://n2.nabble.com/MySQL-getting-a-FeatureWriter-for-modifying-existing-features-in-database-tp4092849p4092849.html
Sent from the geotools-gt2-users mailing list archive at Nabble.com.
------------------------------------------------------------------------------
Join us December 9, 2009 for the Red Hat Virtual Experience,
a free event focused on virtualization and cloud computing.
Attend in-depth sessions from your desk. Your couch. Anywhere.
http://p.sf.net/sfu/redhat-sfdev2dev
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users