troubleshooting Question

Jdbc connection not established

Avatar of sam_2012
sam_2012 asked on
* JDBCJava
5 Comments1 Solution123 ViewsLast Modified:
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.JdbcOdbcDriver");
                  Connection conn = DriverManager.getConnection("jdbc:odbc:Oracle-Hr","HR","orcl");
                  System.out.println(conn.getClass().getName());
            if (conn==null)
            {
                  System.out.println("Connection not established");
            }
            else
            {
                  System.out.println("Connection is  established");
            }
            }
            catch(SQLException e)
            {
                  System.out.println(e);            
            }
            catch(ClassNotFoundException 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.
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros