Here is my java connectivity code to Oracle

public class OracleConnectivity {
    public Connection con;
    
      public Connection getConnection ()

        {       
            try 
            {
               
                 Class.forName("oracle.jdbc.driver.OracleDriver");
                 con=DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:dhanesh","dhanesh","root");
                 Statement s=con.createStatement();
                 s.executeUpdate("insert into test (num,txt) values (2,'hi')");
   
                 s.close();
                 con.close();
            } 
            catch(Exception e)
            {
                System.out.println("Connection failed");
                e.printStackTrace();
            }
            return con;
        }
    public static void main(String[] args) {
        OracleConnectivity O=new OracleConnectivity();
        O.getConnection();
    }
}

The error i am getting is
java.sql.SQLException: Io exception: Connection refused(DESCRIPTION=(TMP=)(VSNNUM=169869568)(ERR=12505)(ERROR_STACK=(ERROR=(CODE=12505)(EMFI=4))))
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:333)
at oracle.jdbc.driver.OracleConnection.<init>(OracleConnection.java:404)
at oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.java:468)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:314)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at dhanesh.OracleConnectivity.getConnection(OracleConnectivity.java:24)
at dhanesh.OracleConnectivity.main(OracleConnectivity.java:40)


i've ojdbc14 jar file in jdk1.6.0->jre->lib->ext folder

please help me out to resolve this error

problem solved, i did insert dhanesh in hostname, after removing that, it's connected

E:\java>java OracleThin
java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:164)
at OracleThin.main(OracleThin.java:8)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.