Exception in thread "main" java.lang.ClassCastException

Exception in thread "main" java.lang.ClassCastException

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 Testjdbc { public Testjdbc() { } // 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.

Testjdbc.java:2:error:package org.postgis doesnot exist Testjdbc.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.

View Answers









Related Tutorials/Questions & Answers:
Exception in thread "main" java.lang.ClassCastException
Exception in thread "main" java.lang.ClassCastException  I am trying to connect the database. I am stuck with this exception that is getting thrown...) { sqle.printStackTrace(); } finally { try {stmt.close();} catch (Exception e
Exception in thread "main" java.lang.ClassCastException
Exception in thread "main" java.lang.ClassCastException  I am trying to connect the database. I am stuck with this exception that is getting thrown...) { sqle.printStackTrace(); } finally { try {stmt.close();} catch (Exception e
Advertisements
exception in thread main java.lang.unsupportedclassversionerror in ubuntu
exception in thread main java.lang.unsupportedclassversionerror in ubuntu  Hi, In Ubuntu I am trying to run Java program and its throwing exception. exception in thread main java.lang.unsupportedclassversionerror in ubuntu How
exception in thread main java.lang.unsupportedclassversionerror in eclipse
exception in thread main java.lang.unsupportedclassversionerror in eclipse  Hi, I am trying to run a library which is from some other project. But it throws exception in thread main java.lang.unsupportedclassversionerror
exception in thread main while running servlet
exception in thread main while running servlet  I got exception in thread main no such method error while running servlet. I have added servlet.api.jar file in classpath.my classpath is C:\Program Files\Apache Software Foundation
exception in thread main java.lang.unsupportedclassversionerror unsupported major.minor version 50.0 - Java Beginners
exception in thread main java.lang.unsupportedclassversionerror unsupported... getting the this error :exception in thread main...!"); } } for example: javac xxx.java-->comping java xxxx:error :exception in thread main
exception in thread main java.lang.unsupportedclassversionerror unsupported major.minor version 50.0 - Java Beginners
exception in thread main java.lang.unsupportedclassversionerror unsupported... is compling but runtime i am getting the exception in thread main.... Thanks  my code is class xxx { public static void main(String
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/mail/util/MailLogger
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/mail/util/MailLogger  Hi, How to solve following error? Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/mail/util/MailLogger
Exception in thread "main" org.hibernate.hql.ast.QuerySyntaxException: TESTING is not mapped [FROM TESTING]
Exception in thread "main" org.hibernate.hql.ast.QuerySyntaxException: TESTING...(HiberTest.java:18) Exception in thread "main...)); } } } couldn't connect to tDB using, SQL statements. Exception in thread "main
Exception in thread
Exception in thread   Hi, In my code following error is coming: Exception in thread "main" java.lang.NoClassDefFoundError: org/json/JSONObject I have imported: import org.json.JSONObject; but its not working. What
Exception in thread
Exception in thread   Hi, In my code following error is coming: Exception in thread "main" java.lang.NoClassDefFoundError: org/json/JSONObject I have imported: import org.json.JSONObject; but its not working. What
Exception in thread
:\mail.jar SendMailTLSDFC Exception in thread "main" java.lang.NoClassDefFoundError...Exception in thread   Hi, I have created a java file for sending a file to my mail. I am using mail.jar file. I am able to create .class file
Exception in Thread
Exception in Thread    i am developing a rmi application in eclipse... client and generate connection with server i have following exception : Blockquote Exception in thread "RMI TCP Connection(idle
Main Thread and Child Thread
and Child Threads used in Programming. Main thread is automatically created when program runs. Child Thread gets created by the main thread . Java Main... 1 this thread is main 1 this thread is Child 2 this thread is Child 3
How to Differenciate Main Thread and Child Thread in Java
How to Differenciate Main Thread and Child Thread in Java  hi... Main Thread and Java Child Thread. Please Suggest any example or online link... Language. These are Java Main Thread and the Child Thread. The Below reference
difference between main thread and child thread?
difference between main thread and child thread?  any one give correct exact difference.   in jsp 7 implicit objects are available those are 1:response->This denotes the data included with the HTTP Response. 2
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException  ... is clicking I getting the error : Exception in thread "AWT-EventQueue-0... { Image m; Thread t; NextPage(final String uname
how to solve the nullPointer Exception in main - Java Beginners
: Exception in thread "main" java.lang.NullPointerException...how to solve the nullPointer Exception in main  New to Java ,pls help me how fix Null pointer Exception in main: two files , split .java another
Java Exception Thread
Java Exception Thread     ... interface( java .lang. thread) Understand Exception in Threads. 1.A class name... is to be normal termination or caught exception.  5.runner = new Thread
Thread
(Exception ex) { } } }; Thread mainth = new Thread(main... should produce the sum of 1 to 10, 11 to 20 and 21to 30 respectively. Main thread...); } catch(Exception ex) { } } }; Thread thread3 = new Thread
Unhandled Exception in Thread
Unhandled Exception in thread are thrown during the execution of the program... to rectify it is to change it. Example of Unhandled exception in Thread: class... Unhandled Exception in Thread are of different types
Thread
Thread  Explain two ways of creating thread in java. Explain at three methods of thread class.   Java Create Thread There are two main... Create Thread There are two main ways of creating a thread. The first is to extend
Thread
main(String [] args) { MyThread m=new MyThread("Thread Started... to the thread constructor eventhough we had created only one thread and if you say we have added to point to the current thread then why we have not added
Thread
Thread  class Extender extends Thread { Extender(Runnable run...(); } public void run(){ System.out.println("Extender Thread is Started :"); //new Thread(new Implementer()).start(); } } class Implementer
Thread
=" + i); } public static void main(string args[]) { A a = new A(); Thread t = new thread(a); t.start(); } } Is it possible to run above program with out...Thread  will this code work..? class A extends Thread { public
java.lang.ClassCastException: java.lang.String - Java Server Faces Questions
What is Java lang ClassCastException  What is the java.lang.ClassCastException in java.lang.String
thread
thread  can parent thread be dead if child thread is not dead
Thread
Thread  Thread Life Cycle
Thread
Thread  what is the use of thread
exception
{ public static void main(String[] args)throws Exception { for (String s... arguments are not equalto two,throw a user defined exception "invalid parameter exception" ,otherwise display the two parameters.   Here is an example
exception
exception  example for numberformat exception   Hi Friend...{ public static void main(String[] args) { try{ String st="Rose...); } catch(Exception e){ System.out.println(e
MAin error
but @ d tym of runnin error in main class is generated Exception in thread "main".java.lang.NoClassFoundDefLoader. : Hello caused...MAin error  Error while running hello program in another dir rather
if i run this prog, i got exeption in thread "main" java.lang.ArrayIndexOutOfBoundsException:0 at Maxof2.main(Maxof2.java:9), whats the resolution for ths?
if i run this prog, i got exeption in thread "main...?  class Maxof2{ public static void main(String args[]){ //taking...{ public static void main(String args[]){ Scanner input=new Scanner(System.in
Exception
Exception  whis is the Arithmetic Exception in java? or define Arithmetic Exception with exp?   Arithmetic Exception occurs, when you divide a number by zero. Example public class TryCatch { public static void main
Thread
Thread  What is multi-threading? Explain different states of a thread... processor system. States of Thread: New state ? After the creations of Thread instance the thread is in this state but before the start() method invocation
Exception
main(String args[])throws Exception { FooException oo=new FooException...Exception  public class FooException extends Exception { public..."); } public void calculate() throws FooException, Exception { try { int
Thread
Thread  what happen when we call the Wait(),Notify() and NotifyAll() methods in the Thread
exception
exception  wHEN RUNTIME EXCEPTION CLASS IS SUB OF EXCEPTION CLASS HOW CAN'T HANDLE UNCHECKED EXCEPTION
exception
exception  chek in and check out exception in java   Please visit the following link: Checked and Unchecked Exception
Java Sleep Thread
Java Thread sleep() is a static method. It sleeps the thread for the given time in milliseconds. It is used to delay the thread. It is used in Applet or GUI programming for animation Java Sleep Thread Example public class
exception
exception  Identify the reason for SQLException exception, which...; Try this: import java.sql.*; class InsertData{ public static void main..."); ps.executeUpdate(); } catch(Exception e
Thread
Thread   there are two threads running at a time.. when am updating a values in database. both thread halt and stop for moment till it get updated into database... so i dnt want thread to get halts for tht moment of period. whats
Thread
;Java throw and throws Whenever we want to force an exception then we use throw keyword. the throw keyword (note the singular form) is used to force an exception. It can also pass a custom message to your exception handling module. Moreover
thread
thread  Hi what are the threads required to excute a programe except main threads? Thanks kalins naik
exception
exception  what is the use of catch block even though we have predefined exception object
exception
defined checked exception ââ?¬Å?InvalidCharcterFoundExceptionââ?¬Â? and creater a block of codes that will handle the exception
Exception
Exception   I was creating a table dynamically but it shows exception i.e shown down Suplier created0 Suplier created0 Suplier created0 Product created0 Product created0 Product created0 Product created0 could not fetch initial
exception
user defined unchecked exception  can we create user defined unchecked exceptions? if so what is the exact use of it in real time?   Please visit the following links: http://www.roseindia.net/java/java-exception/user
EXCEPTION
implements interface1,interface2{ public static void main(String []args
Exception
NullPointerException:ADS_TO_REPLACE_2 class HelloWorld { public static void main

Ads