Home » Open Source » Programming Interfaces » JDBC with Oracle (merged)
icon14.gif  JDBC with Oracle (merged) [message #492482] Mon, 31 January 2011 08:15 Go to next message
dabbang
Messages: 7
Registered: January 2011
Location: India
Junior Member
Hi, I want to know how to connect to Oracle db thorugh JDBC, as i am able to connect through TOAD.When i try to create DSN getting an error " SQLState =08004 [oacle][odbc][ora]".Toad using TSNNAMES,LDAP & SQLNET files, but i can't file listener.ora file under oracle/admin/ path.i just want to know what is the exact problem,o i need to cretae listener.ora if yes how can i create it? ,if no what is simple way to do connectivity ?
Re: JDBC with Oracle (merged) [message #492488 is a reply to message #492482] Mon, 31 January 2011 08:28 Go to previous messageGo to next message
Michel Cadot
Messages: 59791
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Do you use thin or thick JDBC driver?
There is no relation between ODBC/DSN and JDBC.

Regards
Michel
Re: JDBC with Oracle (merged) [message #492490 is a reply to message #492488] Mon, 31 January 2011 09:58 Go to previous messageGo to next message
BlackSwan
Messages: 23055
Registered: January 2009
Senior Member
>I want to know how to connect to Oracle db thorugh JDBC

http://www.orafaq.com/wiki/JDBC#Thin_driver
Re: JDBC with Oracle (merged) [message #492778 is a reply to message #492490] Wed, 02 February 2011 07:58 Go to previous messageGo to next message
dabbang
Messages: 7
Registered: January 2011
Location: India
Junior Member
I can access database through Oracle Toads , can I pull the data through java? If yes what i need to do ?
Re: JDBC with Oracle (merged) [message #492781 is a reply to message #492778] Wed, 02 February 2011 08:28 Go to previous messageGo to next message
Michel Cadot
Messages: 59791
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
You must first answer our questions.

Note that TOAD is NOT an Oracle product.

Regards
Michel

[Updated on: Wed, 02 February 2011 08:29]

Report message to a moderator

Re: JDBC with Oracle (merged) [message #492795 is a reply to message #492781] Wed, 02 February 2011 10:47 Go to previous messageGo to next message
dabbang
Messages: 7
Registered: January 2011
Location: India
Junior Member
I used the THIN driver for it. But getting an exception ClassNotFound-oracle.jdbc.Driver.OracleDriver

import java.sql.*;
class Conn
{
public static void main (String args []) throws ClassNotFoundException,SQLException
{

Class.forName ("oracle.jdbc.Driver.OracleDriver");
System.out.println("Hello");
// Connection conn = DriverManager.getConnection ("jdbc:oracle:thin:@xxx.com", "nnn", "nn1");
// @machineName:port:SID, userid, password
System.out.println("Successfully connected");
}


}

Re: JDBC with Oracle (merged) [message #492798 is a reply to message #492795] Wed, 02 February 2011 11:03 Go to previous messageGo to next message
BlackSwan
Messages: 23055
Registered: January 2009
Senior Member
posted URL shows working code example
Re: JDBC with Oracle (merged) [message #492803 is a reply to message #492795] Wed, 02 February 2011 11:26 Go to previous messageGo to next message
Michel Cadot
Messages: 59791
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Does you CLASSPATH contains "<ORACLE_HOME>/jdbc/lib/classes12.zip"?

I use "DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());" not "Class.forName ("oracle.jdbc.Driver.OracleDriver");".

Regards
Michel
Re: JDBC with Oracle (merged) [message #492809 is a reply to message #492803] Wed, 02 February 2011 12:00 Go to previous messageGo to next message
dabbang
Messages: 7
Registered: January 2011
Location: India
Junior Member
Do i need to down load classes12.zip ?? I have no idea about classes12.zip
Re: JDBC with Oracle (merged) [message #492811 is a reply to message #492809] Wed, 02 February 2011 12:15 Go to previous messageGo to next message
Michel Cadot
Messages: 59791
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
This is the file that contains Oracle classes, you need to put it in your CLASSPATH environment variable. Java will load it automatically. I'm not a Java expert, I just know that in this way, it works. Smile

Regards
Michel
Re: JDBC with Oracle (merged) [message #492932 is a reply to message #492811] Thu, 03 February 2011 12:18 Go to previous messageGo to next message
dabbang
Messages: 7
Registered: January 2011
Location: India
Junior Member
Ok got it now, but when i tried to set Systm Environment i.e CLASSPATH c:\java\...\bin ; c:\oracle\...\lib\classes12.zip , But still getting an error.
when tried with simply CLASSPATH c:\oracle\...\lib\classes12.zip getting an error "NoClassDefinationFound"

When i tried with CLASSPATH c:\java\...\bin getting an error "ClassNotFound: oracle...."

How can i set it ?

Regards
Dabbang Smile
Re: JDBC with Oracle (merged) [message #492935 is a reply to message #492932] Thu, 03 February 2011 12:38 Go to previous messageGo to next message
Michel Cadot
Messages: 59791
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Do you check the file is in the directory c:\oracle\...\lib\.
Note that there should be NO space in CLASSPATH value.

Regards
Michel
Re: JDBC with Oracle (merged) [message #493006 is a reply to message #492935] Fri, 04 February 2011 05:00 Go to previous messageGo to next message
dabbang
Messages: 7
Registered: January 2011
Location: India
Junior Member
Yes I checked the classes12.zip under oracle path. & there is no space between path only ";" is there. Still facing problem.
Re: JDBC with Oracle (merged) [message #493009 is a reply to message #493006] Fri, 04 February 2011 05:06 Go to previous messageGo to next message
Michel Cadot
Messages: 59791
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Post your code, I will check it in my environment.

Regards
Michel
Re: JDBC with Oracle (merged) [message #493030 is a reply to message #493009] Fri, 04 February 2011 05:56 Go to previous messageGo to next message
dabbang
Messages: 7
Registered: January 2011
Location: India
Junior Member
Please Check the Code
import java.sql.*;
class Conn
{
public static void main (String args []) throws ClassNotFoundException,SQLException
{

Class.forName ("oracle.jdbc.Driver.OracleDriver");
System.out.println("Hello");
// Connection conn = DriverManager.getConnection

("jdbc:oracle:thin:@(database)Hostname", "UserID, "Password");
// @machineName:port:SID, userid, password
System.out.println("Successfully connected");
}


}
Re: JDBC with Oracle (merged) [message #493036 is a reply to message #493030] Fri, 04 February 2011 06:16 Go to previous message
Michel Cadot
Messages: 59791
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
C:\>type Conn.java
import java.sql.*;
class Conn
{
public static void main (String args [])
  throws ClassNotFoundException,SQLException
{
// Class.forName ("oracle.jdbc.Driver.OracleDriver");
 DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
 System.out.println("Hello");
 Connection conn = DriverManager.getConnection
                     ("jdbc:oracle:oci8:@mika", "michel", "michel");
 System.out.println("Successfully connected with OCI driver");
 conn.close();
 conn = DriverManager.getConnection
          ("jdbc:oracle:thin:@localhost:1530:mika", "michel", "michel");
 System.out.println("Successfully connected with thin driver");
 conn.close();
}

}

C:\>javac Conn.java

C:\>java Conn
Hello
Successfully connected with OCI driver
Successfully connected with thin driver

C:\>set
CLASSPATH=.;C:\oracle\ora1024\jdbc\lib\classes12.zip
ORACLE_HOME=C:\oracle\ora1024
ORACLE_SID=MIKA
Path=C:\oracle\ora1024\jdk\bin;C:\oracle\ora1024\bin;C:\oracle\ora1024\lib;
C:\oracle\ora1024\OPatch;C:\Perl\bin\;C:\WINDOWS\system32;C:\WINDOWS;
windir=C:\WINDOWS

As I said use "DriverManager.registerDriver" NOT "Class.forName".

Regards
Michel

[Updated on: Fri, 04 February 2011 06:17]

Report message to a moderator

Previous Topic: Present data in table from database in PHP
Next Topic: PL/SQL and AJAX
Goto Forum:
  


Current Time: Wed Nov 26 11:49:11 CST 2014

Total time taken to generate the page: 0.25022 seconds