aspose file tools*
The moose likes JDBC and the fly likes Connect Class Cast Exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Connect Class Cast Exception " Watch "Connect Class Cast Exception " New topic
Author

Connect Class Cast Exception

Nikki Freeman
Greenhorn

Joined: Jul 12, 2006
Posts: 2
Hi,

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;


import com.ibm.rmi.iiop.Connection;

public class SimpleJDBC {

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

Properties properties = new Properties();
properties.put("user","ent_data");
properties.put("password","etgo");

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
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");
}else{
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'");

while(rset.next()){
String firstName = rset.getString("XFIRSTNAME");
System.out.println(firstName);
}

rset.close();
statement.close();
connection.abortConnection();
}
}

}
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.

http://www.oracle.com/technology/software/tech/java/sqlj_jdbc/index.html
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Connect Class Cast Exception