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!
 
 
 


abhilash
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 (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.


Advertisement
View Answers

Related Tutorials/Questions & Answers:
Advertisements
 

 

 

DMCA.com