
I am trying to connect the database. I am stuck with this exception that is getting thrown. Anyone help me please.
Java Code:
import java.sql.*; import org.postgis.*;
public class Test_jdbc { public Test_jdbc() { } // executes single SQL query public static void test(java.sql.Connection conn) { String query = "select nom_com from communes "; Statement stmt = null;
try { stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery(query); String s = ""; while (rs.next()) { // do something with the result s = rs.getString(1); } } catch (SQLException sqle) { sqle.printStackTrace(); } finally { try {stmt.close();} catch (Exception e){e.printStackTrace();} } }
public static void main(String[] argv) { try { Class driver=Class.forName("org.postgresql.Driver"); java.sql.Connection conn=DriverManager.getConnection("jdbc:postgresql://localhost/postGIS","postgres", "postgres");
((org.postgresql.Connection)conn).addDataType("geometry","org.postgis.PGgeometry");
((org.postgresql.Connection)conn).addDataType("box3d","org.postgis.PGbox3d"); test(conn); } catch (Exception ex) { ex.printStackTrace(); } } }
When i am compiling it it throw the error.
Test_jdbc.java:2:error:package org.postgis doesnot exist Test_jdbc.java:35:error:package org.postgresql doesnot exist Test_jdbc.java:37:error:package org.postgresql doesnot exist
can anyone solve this problem its very urgent.
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.