Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Cannot connect to Oracle 9i

 
Sandip Ray
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am new to jsp. I am having a problem to connect to oracle 9i using java. Let me inform you that I have installed Oracle9i in D:\Softwares\oracle with SID name:OraGlobe. I am using jdk 1.6 which is installed in D:\Softwares\Java\jdk1.6. I have also set the environment variable as path=D:\Softwares\Java\jdk1.6\bin.

Now I have written the following code to connect to oracle9i as follows:

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

public class DbCon
{

public static void main(String[] argv)
{

System.out.println("-------- Oracle JDBC Connection Testing ------");

try
{

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

}
catch (ClassNotFoundException e)
{

System.out.println("Where is your Oracle JDBC Driver?");
//e.printStackTrace();
//return;

}

System.out.println("Oracle JDBC Driver Registered!");

Connection connection = null;

try
{

connection = DriverManager.getConnection("jdbcracle:thin:@localhost:1521:OraGlobe","scott","tiger");
}
catch (SQLException e)
{

System.out.println("Connection Failed! Check output console");
e.printStackTrace();
return;

}

if (connection != null)
{
System.out.println("You made it, take control your database now!");
}
else
{
System.out.println("Failed to make connection!");
}
}

}

I saved the above code in a file(using notepad) named DbCon.java & stored in D:\.
On compiling the above file from comand-prompt its showing no error,but while trying to run using the command "java DbCon",getting some weired
result.Please find herwith the screenshot attachment in support of my statement.
Really trying hard to connect to oracle but unable to do so. Tried couple of weeks but failed.Hence need support. Please help

Filename: jdbc.bmp
Description: Compiled & run DbCon.java result
File size: 660 Kbytes
[Download jdbc.bmp] Download Attachment
 
Suraj Bhosale
Greenhorn
Posts: 10
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sandip Ray wrote:Hi,
I am new to jsp. I am having a problem to connect to oracle 9i using java. Let me inform you that I have installed Oracle9i in D:\Softwares\oracle with SID name:OraGlobe. I am using jdk 1.6 which is installed in D:\Softwares\Java\jdk1.6. I have also set the environment variable as path=D:\Softwares\Java\jdk1.6\bin.



As I can see its throwing ClassNotFoundException because you have not set classpath ie. needed for running jdbc programs. To ensure that the ClassNotFoundException is not raised , you need to add the classes12.zip file into classpath varaible. You can find the classes12.zip file in <oracle home>\jdbc\lib\classes12.zip just add this path in Environment variable value. Right click on My Computer go to properties then on left side click on advanced system Settings then in advanced tab you will see Environment Variable click on that, now under system variable field there will be classpath just edit that and add your classes12.zip path here It will somewhat look like this .;C:\Java\jdk1.6.0_29\lib\rt.jar;C:\Java\jdk1.6.0_29\jre;C:\oracle\product\10.2.0\db_1\jdbc\lib\classes12.zip;C:\Apache Software Foundation\Tomcat 5.5\server\lib;C:\Apache Software Foundation\Tomcat 5.5\server\lib\servlet-api.jar

Hope this helps
 
Sandip Ray
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Though after appending the classes12.zip in the CLASSPATH variable, still while trying to run the previous database connection program giving classnotfound exception.

In the Classpath variable the following is there:

.;D:\Softwares\Java\jre1.6\lib\ext\QTJava.zip;D:\Softwares\oracle\ora90\jdbc\lib\classes12.zip.

Is this Ok?

Also find herewith the attachments in support of the above statements.Please help.

Cannot attach the screenshot of program execution from command prompt as its showing:"The total size of the attachments should not be greater than 1,024 kb. The uploaded files have a total of 1,128 kb.". Though the output is same as that of the previous one. Stated in the previous screenshot.

With regards
Sandip Ray
Filename: Env.Variables.bmp
Description: Environmetal Variables
File size: 474 Kbytes
[Download Env.Variables.bmp] Download Attachment
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic