[prev in list] [next in list] [prev in thread] [next in thread]
List: postgis-users
Subject: [postgis-users]
From: Venu Kanaparthy <madhavsinghk () yahoo ! com>
Date: 2003-09-25 1:37:33
Message-ID: 20030925013733.42535.qmail () web21303 ! mail ! yahoo ! com
[Download RAW message or body]
Hi all, I am trying to read feature geometries from posgresql over jdbc in a JSP \
page.
I have a parcel tables with multipolygons. I am getting classcastexception
at following statement,
PGgeometry the_geom = (PGgeometry)recordSet.getObject(2);
I want to read the point, line and polygon geometries and create a GML file.
one more question i have is, PGgeometry class is part of classes that came with
postgresql.jar file. There is one more jar file (postgis.jar), which containts \
POSTGIS
supported geomtries. How can read geometries from postgresql type into postgis?
Is it possible ? Any help will be great.
I am including the source code for jsp file: dbconnect.jsp
<%@ page import="java.sql.*,java.util.*,java.io.*,org.postgis.*,org.postgresql.util.*,org.postgis.MultiPolygon,org.postgis.Geometry,java.lang.*" \
%>
<html> <body>
<% try { Class.forName("org.postgresql.Driver").newInstance(); %>
<h1><font color="blue">Driver loaded !!!! </h1>
<% } catch (ClassNotFoundException ex)
{ System.out.println("Error loading the JDBC driver: " + ex);
%> <h1><font color="red">Error loading the JDBC driver</font></h1>
<% return;
}
String url = "jdbc:postgresql://localhost:5432/test";
String host = "localhost"; String database = "test";
int port = 3306; // String URL = "jdbc:mysql:" + host + ":" + port + ":" + database;
// String URL ="jdbc:mysql://localhost:3306/test";
String username = ""; String password = ""; Connection connection = null;
try{
connection = DriverManager.getConnection(url,"vkanaparthy", "");
// connection = DriverManager.getConnection(URL, username, password);
System.out.println("\nMade Connection OK"); %>
<h1><font color="blue">Database Connection Successfull !!!! </h1>
<%
// connection.close(); // connection = null;
} catch (java.sql.SQLException ex)
{ %>
<h1><font color="red">Dabase Connection Unsuccesful !!!!! + <% ex.printStackTrace(new \
PrintWriter(out)); %></font></h1>
<% System.err.println("Error getting the connection: " + ex); return;
}
try {
// ((org.postgresql.PGConnection)connection).addDataType("geometry","org.postgis.PGgeometry"); \
// ((org.postgresql.PGConnection)connection).addDataType("box3d","org.postgis.PGbox3d"); \
((org.postgresql.PGConnection)connection).addDataType \
("geometry","org.postgis.PGgeometry");
((org.postgresql.PGConnection)connection).addDataType \
("multipolygon","org.postgis.MultiPolygon");
((org.postgresql.PGConnection)connection).addDataType \
("box3d","org.postgis.PGbox3d");
((org.postgresql.PGConnection)connection).addDataType \
("polygon","org.postgis.Polygon");
((org.postgresql.PGConnection)connection).addDataType ("point","org.postgis.Point");
Statement s = connection.createStatement();
// ResultSet r = s.executeQuery("select gid, AsText(the_geom) as geom, type, material \
from sewerlines");
ResultSet r = s.executeQuery("select gid, AsText(the_geom) as geom from parcel");
while( r.next() ) {
// String sgeom = (String)r.getString(1);
PGgeometry the_geom = (PGgeometry)r.getObject(2);
// PGgeometry the_geom = new PGgeometry(sgeom);
int id = r.getInt(1); // String type = r.getString(3); // String mat = \
r.getString(4); %>
<table border=1> <tr><td width=70>
<% // out.println("Row " + geom + " : "+ type + ":" + mat + "\n"); out.println("\n"); \
%>
</td></tr> </table>
<% //out.println(geom.toString());
} connection.close(); } catch(Exception ex1) { %> <% ex1.printStackTrace(new \
PrintWriter(out)); %>
<% } %> <h1> </h1></body> </html>
Exception:
java.lang.ClassCastException at \
org.apache.jsp.dbconnect_jsp._jspService(dbconnect_jsp.java:133) at \
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:137) at \
javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at \
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:210) at \
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295) at \
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241) at \
javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at \
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247) \
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193) \
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256) \
at
---------------------------------
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
[Attachment #3 (text/html)]
<P><FONT color=#0000ff>Hi all, I am trying to read feature geometries from \
posgresql over jdbc in a JSP page.</FONT></P> <P><FONT color=#0000ff>I have a \
parcel tables with multipolygons. I am getting classcastexception</FONT></P> <P><FONT \
color=#0000ff>at following statement, <FONT size=2></P> <P>PGgeometry the_geom = \
(PGgeometry)recordSet.getObject(2); </P> <P>I want to read the point, \
line and polygon geometries and create a GML file.</P> <P>one more \
question i have is, PGgeometry class is part of classes that came with</P> \
<P>postgresql.jar file. There is one more jar file \
(postgis.jar), which containts POSTGIS </P> <P>supported geomtries. How can read \
geometries from postgresql type into postgis?</P> <P>Is it possible ? Any help \
will be great.</P></FONT></FONT> <P><FONT color=#0000ff>I am including the \
source code for jsp file: dbconnect.jsp</FONT></P><FONT color=#0000ff><FONT size=2> \
<P><%@ page import="java.sql.*,java.util.*,java.io.*,org.postgis.*,org.postgresql.util.*,org.postgis.MultiPolygon,org.postgis.Geometry,java.lang.*" \
%></P> <P><html> <body> </P>
<P><% try { \
Class.forName("org.postgresql.Driver").newInstance(); %></P> <P><h1><font \
color="blue">Driver loaded !!!! </h1> </P> <P><% } catch \
(ClassNotFoundException ex)</P> <P>{ System.out.println("Error loading the JDBC \
driver: " + ex);</P> <P>%> <h1><font color="red">Error loading \
the JDBC driver</font></h1></P> <P><% return;</P>
<P>}</P>
<P></P>
<P>String url = "jdbc:postgresql://localhost:5432/test"; </P>
<P>String host = "localhost"; String database = "test";</P>
<P>int port = 3306; // String URL = "jdbc:mysql:" + host + ":" + port + ":" + \
database;</P> <P>// String URL ="jdbc:mysql://localhost:3306/test"; </P>
<P></P>
<P></P>
<P>String username = ""; String password = ""; Connection connection = \
null;</P> <P>try{</P>
<P>connection = DriverManager.getConnection(url,"vkanaparthy", ""); </P>
<P>// connection = DriverManager.getConnection(URL, username, password);</P>
<P>System.out.println("\nMade Connection OK"); %></P>
<P><h1><font color="blue">Database Connection Successfull !!!! \
</h1> </P> <P><% </P>
<P>// connection.close(); // connection = null;</P>
<P>} catch (java.sql.SQLException ex)</P>
<P>{ %></P>
<P><h1><font color="red">Dabase Connection Unsuccesful !!!!! + <% \
ex.printStackTrace(new PrintWriter(out)); %></font></h1></P> \
<P><% System.err.println("Error getting the connection: " + ex); \
return;</P> <P>}</P>
<P></P>
<P>try {</P>
<P>// ((org.postgresql.PGConnection)connection).addDataType("geometry","org.postgis.PGgeometry"); \
</P> <P>// ((org.postgresql.PGConnection)connection).addDataType("box3d","org.postgis.PGbox3d"); \
</P> <P>((org.postgresql.PGConnection)connection).addDataType \
("geometry","org.postgis.PGgeometry");</P> \
<P>((org.postgresql.PGConnection)connection).addDataType \
("multipolygon","org.postgis.MultiPolygon");</P> \
<P>((org.postgresql.PGConnection)connection).addDataType \
("box3d","org.postgis.PGbox3d");</P> \
<P>((org.postgresql.PGConnection)connection).addDataType \
("polygon","org.postgis.Polygon");</P> \
<P>((org.postgresql.PGConnection)connection).addDataType \
("point","org.postgis.Point"); </P> <P>Statement s = connection.createStatement(); \
</P> <P>// ResultSet r = s.executeQuery("select gid, AsText(the_geom) as geom, type, \
material from sewerlines");</P> <P>ResultSet r = s.executeQuery("select gid, \
AsText(the_geom) as geom from parcel");</P> <P>while( r.next() ) { </P>
<P></P>
<P>// String sgeom = (String)r.getString(1); </P>
<P>PGgeometry the_geom = (PGgeometry)r.getObject(2);</P>
<P>// PGgeometry the_geom = new PGgeometry(sgeom); </P>
<P>int id = r.getInt(1); // String type = r.getString(3); // String mat = \
r.getString(4); %></P> <P><table border=1> <tr><td width=70></P>
<P><% // out.println("Row " + geom + " : "+ type + ":" + mat + "\n"); \
out.println("\n"); %></P> <P></td></tr> </table></P>
<P><% //out.println(geom.toString());</P>
<P>} connection.close(); } catch(Exception ex1) { %> <% \
ex1.printStackTrace(new PrintWriter(out)); %></P> <P><% } %> <h1> \
</h1></body> </html></P> <P> </P></FONT></FONT>
<P><FONT color=#0000ff>Exception:</FONT></P>
<P><FONT color=#0000ff>java.lang.ClassCastException at \
org.apache.jsp.dbconnect_jsp._jspService(dbconnect_jsp.java:133) at \
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:137) at \
javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at \
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:210) at \
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295) at \
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241) at \
javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at \
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247) \
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193) \
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256) \
at </FONT></P> <DIV></DIV><p><hr SIZE=1>
Do you Yahoo!?<br>
<a href="http://us.rd.yahoo.com/evt=10469/*http://sitebuilder.yahoo.com">Yahoo! \
SiteBuilder</a> - Free, easy-to-use web site design software
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic