barantamer
12-23-2008, 01:56 AM
Hello,
I am using eclipse and i am trying to connect to oracle 10g db. The weird thing is i had succeeded and then shut down my machine. Then the next morning i tried the run the same code i got the error
SQLException: No suitable driver found for jdbc:oracle:thin:@127.0.0.1:1521:XE
Could not Get Connection
my code is below :
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.SQLException;
public class JDBC {
static String userid="baran", password = "tamer";
static String url = "jdbc:oracle:thin:@127.0.0.1:1521:XE";
static Connection con = null;
private String baran;
public JDBC() throws Exception {
Connection con = getOracleJDBCConnection();
if(con!= null){
System.out.println("Got Connection.");
baran="connected";
DatabaseMetaData meta = con.getMetaData();
System.out.println("Driver Name : "+meta.getDriverName());
System.out.println("Driver Version : "+meta.getDriverVersion());
}else{
System.out.println("Could not Get Connection");
baran="not connected";
}
}
public static Connection getOracleJDBCConnection(){
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); } catch(java.lang.ClassNotFoundException e) {
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
}
try {
con = DriverManager.getConnection(url, userid, password);
} catch(SQLException ex) {
System.err.println("SQLException: " + ex.getMessage());
}
return con;
}
public String getBaran() {
return baran;
}
}
What could be the problem ? any ideas?
I am using eclipse and i am trying to connect to oracle 10g db. The weird thing is i had succeeded and then shut down my machine. Then the next morning i tried the run the same code i got the error
SQLException: No suitable driver found for jdbc:oracle:thin:@127.0.0.1:1521:XE
Could not Get Connection
my code is below :
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.SQLException;
public class JDBC {
static String userid="baran", password = "tamer";
static String url = "jdbc:oracle:thin:@127.0.0.1:1521:XE";
static Connection con = null;
private String baran;
public JDBC() throws Exception {
Connection con = getOracleJDBCConnection();
if(con!= null){
System.out.println("Got Connection.");
baran="connected";
DatabaseMetaData meta = con.getMetaData();
System.out.println("Driver Name : "+meta.getDriverName());
System.out.println("Driver Version : "+meta.getDriverVersion());
}else{
System.out.println("Could not Get Connection");
baran="not connected";
}
}
public static Connection getOracleJDBCConnection(){
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); } catch(java.lang.ClassNotFoundException e) {
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
}
try {
con = DriverManager.getConnection(url, userid, password);
} catch(SQLException ex) {
System.err.println("SQLException: " + ex.getMessage());
}
return con;
}
public String getBaran() {
return baran;
}
}
What could be the problem ? any ideas?