gpt4 book ai didi

java - 使用java从mysql中几何类型的列中获取数据

转载 作者:行者123 更新时间:2023-11-29 06:34:47 25 4
gpt4 key购买 nike

我有一个 mysql 数据库表,其列 GEOMETRY 类型为 geometry。我以前曾成功地使用此语句仅查询表中的 GEOMETRY 列:

 String sql="SELECT AsText(GEOMETRY) from" +tableName+";";

现在,我想查询此表中的所有字段,如下所示:

 String sql="Select * from "+tableName+";";
Statement st=null;
ResultSet rs=null;
try {
st=(Statement) conn.createStatement();
rs=st.executeQuery(sql);
while(rs.next())
{
//...getting other fields
String wkt=rs.getString("AsText(GEOMETRY)");//error
//add all fields to an ArrayList
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

我在这里遇到这个错误:

 Select * from ZMAPERP_equi_GIS_DB;
java.sql.SQLException: Column 'AsText(GEOMETRY)' not found.
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1084)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:987)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:973)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:918)
at com.mysql.jdbc.ResultSetImpl.findColumn(ResultSetImpl.java:1162)
at com.mysql.jdbc.ResultSetImpl.getString(ResultSetImpl.java:5728)
at com.hastha.marerp.googlemaps.DBUtils.getAllFeatures(DBUtils.java:340)
at com.hastha.marerp.googlemaps.LayerLoader.doGet(LayerLoader.java:48)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:314)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)

最佳答案

您的代码:String wkt=rs.getString("AsText(GEOMETRY)"); 是错误发生的地方,因为它正在寻找名为“AsText(GEOMETRY)”的列,但是不再在查询中.. 你有 SELECT * FROM... 所以这和说 SELECT GEOMETRY FROM.. 不是 AsText() 部分是一样的

我会指定字段,这样您就可以查询

SELECT field1, field2, AsText(GEOMETRY) FROM tablename

如果你不想把每一个都写出来,那么你可以像这样在末尾添加 astext

SELECT *, AsText(GEOMETRY) FROM tablename

关于java - 使用java从mysql中几何类型的列中获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25609518/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com