Latest Tutorials| Questions and Answers|Ask Questions?|Site Map

Home Answers Viewqa JDBC Exception in thread "main" java.lang.ClassCastException

Have Programming Question? Ask it here!

Exception in thread "main" java.lang.ClassCastException
0 Answer(s)      2 years ago
Posted in : JDBC

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 ( { // 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("box3d","org.postgis.PGbox3d"); test(conn); } catch (Exception ex) { ex.printStackTrace(); } } }

When i am compiling it it throw the error. org.postgis doesnot exist org.postgresql doesnot exist org.postgresql doesnot exist

can anyone solve this problem its very urgent.

View Answers

Related Tutorials/Questions & Answers: