Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Connect Class Cast Exception

 
Nikki Freeman
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 333
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic