It's not a secret anymore!
The moose likes JDBC and Relational Databases and the fly likes Connect Class Cast Exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Connect Class Cast Exception " Watch "Connect Class Cast Exception " New topic

Connect Class Cast Exception

Nikki Freeman

Joined: Jul 12, 2006
Posts: 2

I'm new to JDBC. I am just trying to do a simple query on an Oracle DB.

For some reason I am getting a ClassCast Exception when I add the properties argument to the DriverManager. When I leave the properties argument out, it runs fine but can't connect to the DB because my user/password for the DB is not the same for my local computer. My code is as follows. Thanks for you help:

* Created on Jul 11, 2006
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
package junit;

import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;


public class SimpleJDBC {

public static void main(String[] args) throws Exception {

Properties properties = new Properties();

String dsURL = "jdbcdbc:EnterpriseTest";

Connection connection;

// ClassCastException here only when I add the properties argument
connection = (Connection) DriverManager.getConnection(dsURL, properties);

if (connection == null){
System.out.println("Sorry, could not establish a connection");
System.out.println("Connection successfull");
Statement statement = (Statement) connection.createInputStream();
int rc = 0;

// put query in here
ResultSet rset = statement.executeQuery("select * from person where xlastname = 'SMITH'");

String firstName = rset.getString("XFIRSTNAME");


stu derby
Ranch Hand

Joined: Dec 15, 2005
Posts: 333
In the long run, you will really really really really not want to use the JDBC-ODBC bridge with Oracle, but use an Oracle-native driver instead, probably the type 4 "thin" driver.
I agree. Here's the link:
subject: Connect Class Cast Exception
It's not a secret anymore!