others (#15) - Can't display routing map (#263) - Message List
I use postgresql8.3.3, postgis1.3.5for postgresql8.3.3 and pgrouting 1.02 on base WindowXP. I have used eclipse-jee-ganymede-SR2-win32 connect database postgresql is success. But when i show my map by HandleDB.java. My data map can't show. This is my Handle.java
package servlet;
import org.postgis.*; import java.sql.*; import java.util.LinkedList?; import java.util.List; import java.util.ListIterator?; import java.util.StringTokenizer?;
public class HandleDB {
private final String HOST = "localhost"; private final String PORT = "5432"; private final String DATABASE = "testdb"; private final String USER = "postgres"; private final String PASSWORD = "chipcoi86"; private final String TABLE = "quan10";
public java.sql.Connection connect(){
java.sql.Connection conn = null; try{
/*
- Load the JDBC driver and establish a connection */
Class.forName("org.postgresql.Driver"); String url = "jdbc:postgresql://" + HOST + ":" + PORT + "/" + DATABASE; conn = DriverManager?.getConnection(url, USER, PASSWORD); /*
- Create a statement and execute a select query. */
return conn;
}catch(Exception e){
e.printStackTrace(); return null;
}
}
/*
- */
public int findNearestEdge(String point, java.sql.Connection conn){
StringTokenizer? poi = new StringTokenizer?(point," "); String[] arr = new String[2]; int i = 0; //push all the words to the array String while(poi.hasMoreTokens()){
arr[i] = String.valueOf(poi.nextElement()); i ++;
} Double x = Double.valueOf(arr[0]); Double y = Double.valueOf(arr[1]); Double shr1 = x - 200; Double shr2 = y - 200; Double ext1 = x + 200; Double ext2 = y + 200;
String sql = "Select gid, source, target, the_geom, " +
"distance(the_geom, GeometryFromText?('POINT(" + point + ")', 4326)) as dist From " + TABLE + " where the_geom && setsrid(" +
"'BOX3D(" + shr1 + " " + shr2 + ", " + ext1 + " " + ext2 + ")'::box3d, 4326) order by dist LIMIT 1";
try{
Statement s = conn.createStatement(); ResultSet? r = s.executeQuery(sql); while(r.next()){
/*
- retrieve source index or target index */
return r.getInt("source");
}
}catch(Exception e){
System.out.println(e);
} return 0;
}
/*
- */
public List<String> runalgorithm (String algorithm, int startindex, int targetindex, java.sql.Connection conn){
String sql = null;
if (algorithm.equals("Dijkstra")){
sql = "Select rt.gid, AsText?(rt.the_geom) As wkt, length(rt.the_geom) As length, " +
TABLE + ".gid " + "From " + TABLE + " ,(Select gid, the_geom From dijkstra_sp_delta( " +
"'" + TABLE + "', " + startindex + " , " + targetindex + " ,200)) as rt Where " +
TABLE + ".gid=rt.gid";
}else if (algorithm.equals("AStar")){
sql = "Select rt.gid, AsText?(rt.the_geom) As wkt, length(rt.the_geom) as length, "
+ TABLE + ".gid " + "From " + TABLE + " ,(Select gid,the_geom From astar_sp_delta( " +
"'" + TABLE + "', " + startindex + " , " + targetindex + " ,200)) as rt Where " + TABLE + ".gid= rt.gid";
}else if (algorithm.equals("ShootingStar")){
sql = "Select rt.gid, AsText?(rt.the_geom) As wkt, length(rt.the_geom) as length, "
+ TABLE + ".gid " + "From " + TABLE + " ,(Select gid,the_geom From shootingstar_sp( " +
"'" + TABLE + "', " + startindex + " , " + targetindex + " ,200, 'length', false, false)) " +
"as rt Where "
+ TABLE + ".gid= rt.gid";
}
try{
Statement s = conn.createStatement(); ResultSet? r = s.executeQuery(sql); List<String> ls = new LinkedList?<String>(); while(r.next()){
/*
- */
ls.add(String.valueOf(r.getObject(2)));
} return ls;
}catch(Exception e){
System.out.println(e); return null;
}
}
/*
- */
public static void main(String args[]){
HandleDB db = new HandleDB(); java.sql.Connection con = db.connect(); int source = db.findNearestEdge("601058.1172986914 1191974.429544109", con); System.out.print(source); List<String> result = db.runalgorithm ("ShootingStar", 1, 30, con);
ListIterator?<String> li = result.listIterator();
while(li.hasNext()){
System.out.println(" " + li.next());
}
}
}
Eclipse alway said that"The requested resource () is not available.". my project run on Apache Tomcat Server 6.0
I don't know why. Please, help me.Sorry, my english very bad.