Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Look up keyword
Like this
1Activity
0 of .
Results for:
No results containing your search query
P. 1
Oracle - Work With Java

Oracle - Work With Java

Ratings: (0)|Views: 15|Likes:
Published by oracle412
oracle foreign key primary key constraints performance tuning MTS IOT 9i block size backup rman corrupted column drop rename recovery controlfile backup clone architecture database archives export dump dmp duplicate rows extents segments fragmentation hot cold blobs migration tablespace locally managed redo undo new features rollback ora-1555 shrink free space user password link TNS tnsnames.ora listener java
oracle foreign key primary key constraints performance tuning MTS IOT 9i block size backup rman corrupted column drop rename recovery controlfile backup clone architecture database archives export dump dmp duplicate rows extents segments fragmentation hot cold blobs migration tablespace locally managed redo undo new features rollback ora-1555 shrink free space user password link TNS tnsnames.ora listener java

More info:

Published by: oracle412 on Jun 17, 2011
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

06/27/2014

pdf

text

original

 
How can I work with Java in the Database? Administration TipsCopyright © Howard Rogers 2001 1/11/2001 Page
1 of 2
 
How can I work with Java in the Database?
You can start by using Java Stored Procedures. Here, I’ll show you how you can make Javado the absolute classic job of updating the salary field for a specified employee in the EMPtable. It’s a useless thing to do in real life: Java is a complex language, and makes doingvery simple things (like ‘update emp set sal=…’) incredibly hard work –and you’d be a mugto do it in real life. But Java’s complexities also mean that doing very complex things aremuch easier than trying to do it with PL/SQL or SQL alone.I’m not taking you down the very-complex-made-easy path (partly because I think we’llboth get lost!). But at least this simple example will give you an idea of how to
start
toget Java working for you.First, copy this script
exactly
into a text editor (notepad or vi, for example), and save it ina file called Test.java (and yes, there’s a capital “T” and a lower case “j” there, and bothare significant). Save it in your Oracle_Home directory (it doesn’t have to be saved there,but it makes things a bit easier later on).
import java.sql.*;public class Test {public static void updateSal(int empid, int salary) {try{Connection connection = DriverManager.getConnection("jdbc:oracle:kprb:");Statement statement = connection.createStatement();int norows = statement.executeUpdate("UPDATE emp SET sal = "+salary+"WHERE empno = "+empid);connection.commit();}catch (SQLException e) {System.out.println(e);}}}
A word to the wise: that statement is case sensitive like you wouldn’t believe! When Iinadvertently tried it with its line 7 reading “…CreateStatement();” the second stageproduced errors complaining that “CreateStatement” was not a method it was aware of.Quite right too: it knows about ‘createStatement’ with the lower case “c”! If you can’tmanage to type all that in
exactly 
, therefore, you’ll find a working, tested version on the“Scripts” page of this website.Second, in your Oracle_Home directory (wherever that might be) type the followingcommand:
loadjava –u scott/tiger@SID –r Test.java
The “SID” there should obviously be replaced with the actual name of the Instance inwhich you wish to run this Java Stored Procedure. That must relate to an entry in yourtnsnames.ora file.

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->