Can someone guide me on Java Oracle 8i connectivity

Hi guys

Can someone guide me step by step on how to do a Java Oracle 8i connectivity.

I have installed
- Oracle 8i Personal Edition
- Apache Tomcat [Req for Servlets and JSP]
- J2SDK 1.4.2[5]

I need to access and write to oracle database.

I cant recollect all the odbc creation , dsn entries etc etc .............

Step By Step setup with Servlet , applet , fsp programs plzzzzzzzzzzzz

Someone help me.
 
Since you have Oracle 8i installed, you can connect to the db using Oracle's own JDBC drivers.
1. Just do a search for this file classes12.zip/classes12.jar on your Oracle installation folder and append the path to any one of them in your system CLASSPATH.
2. Ensure you have set a JAVA_HOME env variable pointing to your JDK installation folder.
3. Ensure you have appended "%JAVA_HOME%\bin" to your PATH env variable.
4. Assuming you have created the default database alongwith the db installation. Else you can create a db using the installed Oracle db tools.
5. In your Java code try the following:
import java.sql.*;

public class TestConnectDB {
public static void main(String[] a) throws Exception {
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection connection = null;
try {
connection = DriverManager.getConnection("<user>", "<password>", "jdbc:eek:racle:thin : @ <host>:<port>:<db sid>");
} finally {
// Clean up your resources here.
if (connection != null) {
connection.close();
}
}
}
}

The first parameter to DriverManager.getConnection is your db user, then your db user password and then comes the connect string. This connect string is specific to the db in question. In this case since we are using the Oracle jdbc driver to connect, the prefix "jdbc:eek:racle:thin:mad:" part remains same. You will have to fill up the values for "host" ( can give as localhost ) and "port" ( by default is 1521 ) and "db sid" ( the name of the db you had given at time of creation ).

You can follow the same approach for connecting to the db from any Java class. However if you are running the application from something like Tomcat server there is yet another way by configuring something called "database connection pools" in Tomcat itself. For now, try this method above and I'll describe the other method once you are comfortable with this one.
 
The file is getting complied but its not executed at all.

Here is my code

import java.sql.*;

public class TestConnectDB
{

public static void main(String[] a) throws Exception

{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection connection = null;

try
{
connection = DriverManager.getConnection("scott","tiger","jdbc:eek:racle:thin:mad:localhost:1521/test:emp");
}

finally

{
// Clean up your resources here.
if (connection != null)
{
connection.close();
}
}
}
}

I am using Jcreator Pro to write and compile code.

Can u help me with setting this up on WinXP
1. Just do a search for this file classes12.zip/classes12.jar on your Oracle installation folder and append the path to any one of them in your system CLASSPATH.
2. Ensure you have set a JAVA_HOME env variable pointing to your JDK installation folder.
3. Ensure you have appended "%JAVA_HOME%\bin" to your PATH env variable.

Also i didnt find the classes.* file on my entire C Drive

I havent done this on WinXP system i was using win98 only.
There aint any autoexec.bat file here for winxp where i cud enter all the path settings.

Also i have a table called emp which has all the employee data.

This is what i get after i run the compiled file.
javaoracle5jb.gif
 
Thats weird. If you have Oracle 8i installed, classes12.jar/.zip should be available in one of the Oracle installation folders. This jar file contains the Oracle JDBC drivers.
Did you do a typical installation or did you customize the install? If you cannot find that jar file, try this link Oracle JDBC driver download

Regarding the update of environment variables, since you are working on WinXP it is much more simpler. Since you are using JCreatorPro, that should take care of invoking the java compiler correctly. So you do not have to worry about setting the JAVA_HOME environment variable. However if you had used something like Notepad to write code, you will need to know these steps.
Goto Control Panel->System->click on Advanced tab->Click on Environment variables.
There are two kinds of environment variables - User and System. User variables are only for the user who is logged on. System variables are applicable for everybody who logs onto the system.
Click on the "New" button below the list of System variables and type in the name as JAVA_HOME. Give the value as the folder to where you have installed the JDK. Say if you had installed it on "C:\Java\j2sdk1.4.2", just type in that value as it is and click on OK.
And then look for the variable named PATH in the System variables list. Select that and click on the "Edit" button. Now you can prefix the following string to the already existing value.
.;%JAVA_HOME%\bin;
And then click on OK.
Then look for the variable named CLASSPATH, if it is not there, create one by clicking on the "New" button. And then give the following value.
.;<location of the file classes12.jar including the name of the file>;
This should ensure that jar file is available for everybody who logs onto the system.
 
Ya i am trying each and everthing.

Still no success will try more and let u guys know abt it for sure.

Vignesh that oracle downlaod req username and password
 
Sorry Quady I forgot about the registration part. You could create a new userid for yourself - it is a free registration and gives you access to all the stuff from oracle.com.
 
Why don't you use Oracle XE with JDK 1.5/1.6-beta2? Also, Oracle has clearly
indicated that oracle.jdbc will be deprecated in near future. The JDBC 1.0 style
connection methods, like Class.forName etc are getting old.

I use OracleDataSource for JDBC connections, which doesn't require that driver
oracle.jdbc.driver.OracleDriver be loaded beforehand. It's more reliable, portable,
future-proof and easy to use than previous JDBC 1.0 techniques.

I suggest that you download and install Oracle XE, which is free for both development
and deployment, even for commercial use. Then fetch JDK 1.6-beta2 from Sun.

Required Type4 thin driver comes with Oracle XE, so you don't need to worry
about downloading it separately etc. And here's an ODS sample for you:
OracleDataSource Demo : Java examples (example source code) » Database SQL JDBC » Oracle JDBC
 
Back
Top