Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

problem while accessing oracle using JDBC

431879Dec 22 2004 — edited Dec 23 2004
Here I was caught up with small problem , I was just written a small program to access oracle database using JDBC driver



But I cant able to access that database but through oracle client(SQL*PLUS) I am able to access the database and I am issuing queries and getting the results





My code is like as below -----------------------------



import oracle.jdbc.driver.OracleDriver;

import java.sql.*;

public class TestDriver

{

public static void main(String[] args)

{

try{

Class.forName("oracle.jdbc.OracleDriver");

Connection coll = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:EPS","system","manager");

PreparedStatement ps = coll.prepareStatement("select * from employee");

ResultSet rs = ps.executeQuery();

while(rs.next()){

System.out.println(rs.getString("ename"));



}

coll.close();

}catch(Exception e){

e.printStackTrace();

}

}

}







the error I am getting is like as below





java.sql.SQLException: Io exception: The Network Adapter could not establish the connection

at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:124)

at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:161)

at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:273)

at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:318)

at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:343)

at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:147)

at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:31)

at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:545)

at java.sql.DriverManager.getConnection(Unknown Source)

at java.sql.DriverManager.getConnection(Unknown Source)

at TestDriver.main(TestDriver.java:9)







after installing oracle in my machine I had already successfully done some work with JDBC



I was already deployed entity beans(CMP) in JBOSS using oracle data source



But in the middle I don’t know what happened my entity bean is not working



After that I had written small jdbc program to access database



It is not working it is throwing the exception like as above



But through the SQL*PLUS I am accessing the oracle properly



Can anybody help me in this regard



And tell me the reason behind this



Thanks & Regards

Veeranjaneyulu Bonthu
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 20 2005
Added on Dec 22 2004
1 comment
956 views