[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&nbsp; 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);&nbsp; </P> <P>I want to read the&nbsp; point, \
line and polygon geometries&nbsp; and create&nbsp; a GML file.</P> <P>one more \
question i have is, PGgeometry class is part of&nbsp; classes that came with</P> \
<P>postgresql.jar file.&nbsp; There is one more jar&nbsp; file \
(postgis.jar),&nbsp;which containts POSTGIS </P> <P>supported geomtries. How can read \
geometries from postgresql type into postgis?</P> <P>Is it possible ?&nbsp; Any help \
will be great.</P></FONT></FONT> <P><FONT color=#0000ff>I am including the&nbsp; \
source code for jsp file: dbconnect.jsp</FONT></P><FONT color=#0000ff><FONT size=2> \
<P>&lt;%@ page import="java.sql.*,java.util.*,java.io.*,org.postgis.*,org.postgresql.util.*,org.postgis.MultiPolygon,org.postgis.Geometry,java.lang.*" \
%&gt;</P> <P>&lt;html&gt; &lt;body&gt; </P>
<P>&lt;%&nbsp;&nbsp; try&nbsp; {&nbsp; \
Class.forName("org.postgresql.Driver").newInstance(); %&gt;</P> <P>&lt;h1&gt;&lt;font \
color="blue"&gt;Driver loaded !!!! &lt;/h1&gt; </P> <P>&lt;% } catch \
(ClassNotFoundException ex)</P> <P>{ System.out.println("Error loading the JDBC \
driver: " + ex);</P> <P>%&gt;&nbsp; &lt;h1&gt;&lt;font color="red"&gt;Error loading \
the JDBC driver&lt;/font&gt;&lt;/h1&gt;</P> <P>&lt;%&nbsp; 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 = "";&nbsp; 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"); %&gt;</P>
<P>&lt;h1&gt;&lt;font color="blue"&gt;Database Connection Successfull !!!! \
&lt;/h1&gt; </P> <P>&lt;% </P>
<P>// connection.close(); // connection = null;</P>
<P>} catch (java.sql.SQLException ex)</P>
<P>{ %&gt;</P>
<P>&lt;h1&gt;&lt;font color="red"&gt;Dabase Connection Unsuccesful !!!!! + &lt;% \
ex.printStackTrace(new PrintWriter(out)); %&gt;&lt;/font&gt;&lt;/h1&gt;</P> \
<P>&lt;%&nbsp; System.err.println("Error getting the connection: " + ex);&nbsp; \
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);&nbsp; // String type = r.getString(3); // String mat = \
r.getString(4); %&gt;</P> <P>&lt;table border=1&gt; &lt;tr&gt;&lt;td width=70&gt;</P>
<P>&lt;% // out.println("Row " + geom + " : "+ type + ":" + mat + "\n"); \
out.println("\n"); %&gt;</P> <P>&lt;/td&gt;&lt;/tr&gt; &lt;/table&gt;</P>
<P>&lt;% //out.println(geom.toString());</P>
<P>}&nbsp; connection.close();&nbsp; } catch(Exception ex1) { %&gt;&nbsp; &lt;% \
ex1.printStackTrace(new PrintWriter(out)); %&gt;</P> <P>&lt;% } %&gt; &lt;h1&gt; \
&lt;/h1&gt;&lt;/body&gt; &lt;/html&gt;</P> <P>&nbsp;</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