<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