Reputation: 4452
I am trying to develop a Java EE application that connect to an Oracle database. I am using ojdbc6 jar. I am reading the database info from property file.
package com.varun.util;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;
import com.arjuna.ats.internal.arjuna.recovery.Connection;
public class DbUtil {
private static Connection connection = null;
public static Connection getConnection(){
if(connection!=null)
{
return connection;
}
else
{
try{
Properties prop=new Properties();
InputStream inputStream=DbUtil.class.getClassLoader().getResourceAsStream("/db.properties");
prop.load(inputStream);
String driver = prop.getProperty("driver");
String url = prop.getProperty("url");
String user = prop.getProperty("user");
String password = prop.getProperty("password");
Class.forName(driver);
connection = (Connection) DriverManager.getConnection(url, user, password);
}catch(ClassNotFoundException e)
{
e.printStackTrace();
}
catch (SQLException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return connection;
}
}
}
I am getting an exception saying:
java.lang.ClassCastException: oracle.jdbc.driver.T4CConnection cannot be cast to com.arjuna.ats.internal.arjuna.recovery.Connection
I am not getting the root cause. I have changed the jar file as well, but still it is throwing the same error.
Upvotes: 0
Views: 8131
Reputation: 168
Problem with your import.
use java.sql.Connection.
Problem get solved.
Upvotes: 0
Reputation: 32145
I think the problem is with your import, check if you have this import in your code:
import com.arjuna.ats.internal.arjuna.recovery.Connection;
It should be :
import java.sql.Connection;
Take a look at This tutorial.
Upvotes: 1
Reputation: 4015
try to change the import from
import com.arjuna.ats.internal.arjuna.recovery.Connection;
to
import java.sql.Connection;
Upvotes: 2
Reputation: 2091
DriverManager.getConnection(url, user, password)
returns an instance of 'oracle.jdbc.driver.T4CConnection', and you are attempting to cast it to 'com.arjuna.ats.internal.arjuna.recovery.Connection'. This is the cause for your error.
Upvotes: 1
Reputation: 2525
Fix your import for Connection
. It must not be com.arjuna.ats.internal.arjuna.recovery.Connection
.
Upvotes: 1