Latest Tutorials| Questions and Answers|Ask Questions?|Site Map

Home Answers Viewqa JDBC how to resolve this JDBC Error?

View Questions and Answers by Category


Have Programming Question? Ask it here!

Ravi kumar
how to resolve this JDBC Error?
0 Answer(s)      2 years and 4 months ago
Posted in : JDBC

i am trying to Exceute this code:

import java.sql.DatabaseMetaData;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class ConnectionDemo{
    public static void main(String args[])throws ClassNotFoundException, SQLException{
        Connection con = null;
        String driverClass = "oracle.jdbc.driver.OracleDriver";
        String dburl = "jdbc:oracle:oci:@localhost:1521:orcl";
        String dbuser = "scott";
        String dbpassword = "tiger";
        con = DriverManager.getConnection(dburl, dbuser, dbpassword);
        if(con== null){
            System.out.println("Not Connected to DataBase");
        DatabaseMetaData dm = con.getMetaData();
        String pn = dm.getDatabaseProductName();
        String pv = dm.getDatabaseProductVersion();
        System.out.println("Connected to :  "+pn);
        System.out.println("Version of DataBase is : "+pv);


the above programe is compiled successfully. i have also set the classpath to : ojdbc6.jar file but when i am executing this code i am getting this Error:

Exception in thread "main" java.sql.SQLException: ORA-12505: TNS:listener does n
ot currently know of SID given in connect descriptor

        at oracle.jdbc.driver.DatabaseError.throwSqlException(
        at oracle.jdbc.driver.T2CConnection.checkError(
        at oracle.jdbc.driver.T2CConnection.logon(
        at oracle.jdbc.driver.PhysicalConnection.<init>(
        at oracle.jdbc.driver.T2CConnection.<init>(
        at oracle.jdbc.driver.T2CDriverExtension.getConnection(T2CDriverExtensio
        at oracle.jdbc.driver.OracleDriver.connect(
        at java.sql.DriverManager.getConnection(
        at java.sql.DriverManager.getConnection(
        at ConnectionDemo.main(

View Answers

Related Tutorials/Questions & Answers: