jQuery in Action, 2nd edition*
The moose likes JDBC and the fly likes connection of JDBC with oracle 9i database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "connection of JDBC with oracle 9i database" Watch "connection of JDBC with oracle 9i database" New topic

connection of JDBC with oracle 9i database

harshada patil
Ranch Hand

Joined: Mar 12, 2011
Posts: 96
how to make connection of JDBC with oracle 9i database? which driver should i install..?
Soumyajit Hazra
Ranch Hand

Joined: Jun 26, 2007
Posts: 136
Use oracle.jdbc.driver.OracleDriver.class present in classes12.jar.

Java Programmer | SCJP 1.5 | SCWCD 1.4
Ankit Tripathi
Ranch Hand

Joined: Oct 17, 2009
Posts: 186
Hi Harshada,
I think you are beginning with JDBC.right?
Go through the link Link.
You'll get more than enough for beginners....
harshada patil
Ranch Hand

Joined: Mar 12, 2011
Posts: 96
previously i made connection of JDBC with ms access through "data source" (ODBC) and it worked.
now i want to use table created in oracle 9i, what are the steps for doing it..?
harshada patil
Ranch Hand

Joined: Mar 12, 2011
Posts: 96
Exception in thread "main" java.sql.SQLException: The Network Adapter could not establish the connection
at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:70)
at oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:133)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:199)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:480)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:413)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:508)
at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:203)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:33)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:510)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at Main.main(Main.java:24)
Caused by: oracle.net.ns.NetException: The Network Adapter could not establish the connection
at oracle.net.nt.ConnStrategy.execute(ConnStrategy.java:328)
at oracle.net.resolver.AddrResolution.resolveAndExecute(AddrResolution.java:421)
at oracle.net.ns.NSProtocol.establishConnection(NSProtocol.java:630)
at oracle.net.ns.NSProtocol.connect(NSProtocol.java:206)
at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:966)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:292)
... 7 more
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:519)
at java.net.Socket.connect(Socket.java:469)
at java.net.Socket.<init>(Socket.java:366)
at java.net.Socket.<init>(Socket.java:180)
at oracle.net.nt.TcpNTAdapter.connect(TcpNTAdapter.java:127)
at oracle.net.nt.ConnOption.connect(ConnOption.java:126)
at oracle.net.nt.ConnStrategy.execute(ConnStrategy.java:306)
... 12 more

please help me with this.. i'm doing program in Netbeans
sudheer yathagiri kumar
Ranch Hand

Joined: Mar 22, 2011
Posts: 35

found classes12.jar file in the ora_home and copy the file in the classpath of environment variables of system and paste it as a new class path and execute the program ...

in netbeans :

go to your project area-->libraries-->add jar file click and browse the classes12.jar

harshada patil
Ranch Hand

Joined: Mar 12, 2011
Posts: 96
i added classes.jar file lib of my project but still getting the same error..
Ankit Tripathi
Ranch Hand

Joined: Oct 17, 2009
Posts: 186
Hi Harshada,

Most possibly error is in Connection URL.

1.Check out if Connection URL is in format-
Connection conn = DriverManager.getConnection("jdbcracle:type of driver:@computer where your oracle client lies:Port No:Service Name","User Name", "Password");

Most possibly values should be-

type of driver-thin

computer where your oracle database instance lies-localhost or

Port No-1521

Service Name-XE

User Name & Password-your user name and password for oracle database instance.

Check out if Port No and Service Name are same as defined in $ORACLE_HOME/network/admin/tnsnames.ora(network connection configuration file) for oracle client.

2.The TNSListener has not been started.Start it with command-

C:\>lsnrctl start

3.Also try to add "ojdbc14.jar" in place of classes12.jar in your classpath.

Avi Abrami
Ranch Hand

Joined: Oct 11, 2000
Posts: 1121

I suggest you visit this Web page.

Good Luck,
harshada patil
Ranch Hand

Joined: Mar 12, 2011
Posts: 96
Thanks all for Reply

problem was in 'Service Name' , i changed it and now its working
I agree. Here's the link: http://aspose.com/file-tools
subject: connection of JDBC with oracle 9i database
Similar Threads
Problem in connection
Type 4
ejb database mapping
dbcp with tomcat 5.0?
application hangs at closing the database connection