About
Pricing
Community
Teams
Start Free Trial
Log in
Swaminathan K
asked on
2/1/2019
Jdbc connection not established
Hi Team ,
Below is the code Iam using running jdbc application , Iam new to Java . Iam not getting the excpected output
folder NAme : jdbcprograms
in this folder I have ojdbc6.jar and DBConnection.java file and class file.
import java.sql.*;
public class DBConnection
{
public static void main(String [] args)
{
try
{
Class.forName("jdbc.odbc.J
dbcOdbcDri
ver");
Connection conn = DriverManager.getConnectio
n("jdbc:od
bc:Oracle-
Hr","HR","
orcl");
System.out.println(conn.ge
tClass().g
etName());
if (conn==null)
{
System.out.println("Connec
tion not established");
}
else
{
System.out.println("Connec
tion is established");
}
}
catch(SQLException e)
{
System.out.println(e);
}
catch(ClassNotFoundExcepti
on e)
{
System.out.println(e);
}
catch(Exception e)
{
System.out.println(e);
}
}
}
When I run the code as below , I get the below output , but not getting the connection established output. Any help is really appreciated
D:\JdbcPrograms>java -jar ojdbc6.jar DBConnection
Oracle 11.2.0.1.0 JDBC 4.0 compiled with JDK6
Expected Output
Class Name Output for Connection Class
Connection established.
* JDBC
Java
5
1
Last Comment
CEHJ
8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
CEHJ
2/2/2019
THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Swaminathan K
2/2/2019
ASKER
D:\JdbcPrograms>java -cp ojdbc6.jar;. DBConnection
java.lang.ClassNotFoundExc
eption: jdbc.odbc.JdbcOdbcDriver
getting the above error
CEHJ
2/2/2019
Is that jar in
that
directory? If so, it doesn't contain the driver
Swaminathan K
2/3/2019
ASKER
Thanks a lot. I kept the correct jar file in the folder it ran successfully
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
CEHJ
2/5/2019
:)
java.lang.ClassNotFoundExc
getting the above error