Unformatted text preview:

CMSC424 Oracle JDBC Cluster FAQ Page 1 Oracle Database Access With Java JDBC Frequently Asked Questions This note is meant to answer a lot of questions I ve been getting in trying to get my project up and running for CMSC 424 My database is intended to access the Oracle server running from the class cluster and do this by using the facilities of Java and most especially the Java module called JDBC Java Database Connectivity Everything I m going to pass on is mostly stuff I found by spending hours reading every public file on marple poring through the online Oracle documentation and occasionally asking some of my project team members who had more Oracle experience than I thanks Brett 1 LOGGING INTO ORACLE First the method used to log in to Oracle has a lot of problems with it Instead of trying to tell you what s wrong with the posted method I ll just give you a method that I know works explain what it does and let it go there When you log into the cluster the first thing you want to do is set your environment up Here s the command that does that source usr local bin coraenv That will prompt you for a couple of things just hit return the defaults will serve just fine Next you need to add the path to the Oracle executables to your system command path and you need to tell the system to update it s hash list of those commands so it can find Oracle s sqlplus This is two commands In entering this next command I m making use of a command called dbhome Go ahead next time you re on the cluster type dbhome All it does is echo to the screen the path to the top of the Oracle directories I m going to surround the dbhome command with back quotes so I can get the result into the command line Note that these are back quotes and if you replace them with regular OR double quotes shame on you setenv PATH dbhome bin PATH rehash OK at this point you should be able to enter sqlplus at the command prompt and not get a rude answer from Unix depending on your definition of rude This is where Oracle prompts you for your username and password and this is also done wrong in the original documentation so watch what I do here I m going to stick the values USERNAME and PASSWORD in the example You replace USERNAME with your Oracle username and PASSWORD with your Oracle password This is not your cluster password which I don t deal with in any way at all in this whole document The last string is js424 and is the name they gave to Dr Saltz s class when they arranged the network connection You don t want to change this As an example my own username is js42430 but I still stick just js424 at the end of the string OK here s what you enter CMSC424 Oracle JDBC Cluster FAQ Page 2 Enter user name USERNAME PASSWORD js424 Don t change the location of either the slash or the sign they re fine just where they are The system won t even bother with the extra prompt for password since you ve already entered it 2 Getting Java Connected 2 1 Getting The Oracle Driver I m writing this from my own perspective which is connecting to the cluster Oracle server from my home machine picnic mat net which runs Unix It s possible that some parts of what I m going to tell you might have to be changed in a small way when using Windows as your connection host I ll detail the changes you ll need to do it from the class cluster itself First you need to get the Oracle driver sourced into Java The Oracle JDBC drivers are in a file located at note the back quotes again dbhome jdbc lib classes111 zip If you re like me and connecting from outside the cluster then you have to actually get this file and copy it somewhere on your home machine I stuck a copy of it in my CMSC 424 Java work directory you ll figure something similar To get Java to notice it though you have to tell Java about it via the CLASSPATH variable Unlike the PATH variable which just wants to know the directories the CLASSPATH needs the entire filename Since I have class111 zip in my local work directory I add that file to my CLASSPATH like so setenv CLASSPATH classes111 zip CLASSPATH Under Windows setting the CLASSPATH is a little different set CLASSPATH classes111 zip CLASSPATH Under Windows don t add any extra spaces in that command at all Do it just like I showed If your classes111 zip isn t in the current directory modify that part of the command to show the entire path to the classes111 zip The way I ve shown it it defaults to using the current directory but you may not want it that way 2 2 Connecting To The Oracle Driver The JDBC statement that does the connection looks like this Class forName oracle jdbc driver OracleDriver This throws an SQLException so you should arrange to catch it and read the error return If you get an error at this point it s a file access error getting to classes111 zip not a network error Whatever you do don t unzip the classes111 zip file it s fine just the way it is Java knows and understands zip files CMSC424 Oracle JDBC Cluster FAQ Page 3 2 3 Connecting To Oracle This next part is the login sequence Again I m going to paste in USERNAME and PASSWORD and again these are your Oracle username and password NOT your cluster username or password I don t need or want your cluster password and neither does Oracle If you re located on the cluster you have two choices of drivers to use now either the oci8 driver or the thin driver The oci8 driver is a high performance driver but it uses a local shared C library This means if you try to use this driver on your home machine it won t work Don t bother copying the library onto your home machine unless you happen to be running a Digital Alpha machine running Digital Unix DUX at home The shared library is code compiled only for that environment and won t work without it To get it to work on the cluster you have to modify your LD LIBRARY PATH variable just like the PATH and CLASSPATH have been changed Here s what you d enter to get the shared library for the oci8 driver enabled setenv LD LIBRARY PATH dbhome lib LD LIBRARY PATH I don t use the oci8 library because while it s high performance it s as portable as a lead weight The other driver also in the classes111 zip file is called the thin driver and works just fine I think most folks reading this FAQ will find that it works …


View Full Document

UMD CMSC 424 - Oracle Database Access

Documents in this Course
Lecture 2

Lecture 2

36 pages

Databases

Databases

44 pages

Load more
Loading Unlocking...
Login

Join to view Oracle Database Access and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Oracle Database Access and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?