BLOBs and CLOBs: Storing large fields in a table with the other data
is not necessarily the optimum place especially if the data has a
variable size. One way to handle large, variable sized objects is with the Large Objects (LOs! type. LOs use a locator, essentially a pointer, in the database record that points to the real database field. "here are two types of LOs: inary Large Objects (LOs! and #haracter Large Objects (#LOs!. $hen you access a LO or #LO, the data is not copied to the client. "o retrieve the actual data from a result set, you have to retrieve the pointer with a call to BLOB blob=getBlob(1) or CLOB clob=getClob(1), and then retrieve the data with a call to blob.getBinaryStream() or clob.getBinaryStream(). y default, %&# statements are processed in full auto'commit mode. Storing Classes, Images and Other Large Objects (any databases can store binary data as part of a row if the database field is assigned a long raw, longvarbinary, or other similar type. "hese fields can accommodate up to two )igabytes of data. "his means if you can convert the data into a binary stream or array of bytes, it can be stored and retrieved from the database in the same way you would store a string or double. "his techni*ue can be used to store and retrieve images and %ava objects. Storing and retrieving an image: +t is very easy to store an object that can be serialized or converted to a byte array. ,nfortunately, java.awt.Image is not Serializable. -owever, as shown in this ne.t code e.ample, you can store the image data to a file and store the the information in the file as bytes in a database binary field. int itemnumber=44!"# $ile %ile = new $ile(itemnumber&'.j(g')# $ileIn(utStream %i) = new $ileIn(utStream(%ile)# *re(are+Statement ()tmt = con.(re(areStatement( 'u(+ate auctionitem) )et t,eimage=- w,ere i+= -')# ()tmt.)etBinaryStream(1. %i). (int)%ile.lengt,())/ ()tmt.)etInt(0. itemnumber)# ()tmt.e1ecute2(+ate()# ()tmt.clo)e()# %i).clo)e()# "o retrieve this image and create a byte array that can be passed to createImage, do the following: int itemnumber=44!"# byte34 imageByte)#
*re(are+Statement ()tmt = con.(re(areStatement( ')elect t,eimage %rom auctionitem) w,ere i+= -')# ()tmt.)etInt(1. itemnumber)# 5e)ultSet r)=()tmt.e1ecute6uery()# i%(r).ne1t()) 7 imageByte) = r).getByte)(1)# 8 ()tmt.clo)e()# r).clo)e()# Image auctionimage = 9ool:it.get;e%ault9ool:it().createImage( imageByte))# Storing and retrieving an object: / class can be serialized to a binary database field in much the same way as the image was in the previous e.ample. +n this e.ample, the 5egi)trationIm(l class is changed to support default serialization by adding im(lement) Serializable to the #lass declaration. 0e.t, a Byte<rrayIn(utStream is created to be passed as the %&# inary Stream. "o create the Byte<rrayIn(utStream, 5egi)trationIm(l is first piped through an ObjectOut(utStream to an underlying Byte<rrayIn(utStream with a call to 5egi)trationIm(l.writeObject "he Byte<rrayIn(utStream is then converted to a byte array, which can then be used to create the Byte<rrayIn(utStream. "he create method in 5egi)trationServer.java is changed as follows: (ublic regi)tration.5egi)tration*= create( String t,eu)er. String (a))wor+. String emaila++re)). String cre+itcar+) t,row) regi)tration.Create>1ce(tion7 +ouble balance=# Connection con = null# *re(are+Statement () = null## try 7 con=getConnection()# 5egi)trationIm(l reg= new 5egi)trationIm(l()# reg.t,eu)er = t,eu)er# reg.(a))wor+ = (a))wor+# reg.emaila++re)) = emaila++re))# reg.cre+itcar+ = cre+itcar+# reg.balance = balance# Byte<rrayOut(utStream regStore = new Byte<rrayOut(utStream()# ObjectOut(utStream regObjectStream = new ObjectOut(utStream(regStore)# regObjectStream.writeObject(reg)# byte34 regByte)=regStore.toByte<rray()# regObjectStream.clo)e()# regStore.clo)e()# Byte<rrayIn(utStream reg<rrayStream = new Byte<rrayIn(utStream(regByte))# ()=con.(re(areStatement( 'in)ert into regi)tration ( t,eu)er. t,ecla))) value) (-. -)')# ().)etString(1. t,eu)er)# ().)etBinaryStream(0. reg<rrayStream. regByte).lengt,)# i% (().e1ecute2(+ate() ?= 1) 7 t,row new Create>1ce(tion ()# 8 5egi)tration*= (rimary=ey = new 5egi)tration*=Im(l()# (rimary=ey.t,eu)er(t,eu)er)# return (rimary=ey# 8 catc, (IO>1ce(tion ioe) 7 t,row new Create>1ce(tion ()# 8 catc, (Create>1ce(tion ce) 7 t,row ce# 8 catc, (S6L>1ce(tion )@e) 7 Sy)tem.out.(rintln(')@e='&)@e)# t,row new Create>1ce(tion ()# 8 %inally 7 try 7 ().clo)e()# con.clo)e()# 8 catc, (>1ce(tion ignore) 7 8 8 8 "he object is retrieved and reconstructed by e.tracting the bytes from the database, creating a Byte<rrayIn(utStream from those bytes to be read from an ObjectIn(utStream, and calling rea+Object to create the instance again. "his ne.t e.ample shows the changes needed to the 5egi)trationServer.re%re), method to retrieve the registration instance from the database. (rivate 5egi)tration re%re),(5egi)tration*= (:) t,row) $in+er>1ce(tion 7 i% ((: == null) 7 t,row new $in+er>1ce(tion ()# 8 Connection con = null# *re(are+Statement () = null# try 7 con=getConnection()# ()=con.(re(areStatement(' )elect t,ecla)) %rom regi)tration w,ere t,eu)er = -')# ().)etString(1. (:.t,eu)er())# ().e1ecute6uery()# 5e)ultSet r) = ().get5e)ultSet()# i%(r).ne1t())7 byte34 regByte) = r).getByte)(1)# Byte<rrayIn(utStream reg<rrayStream = new Byte<rrayIn(utStream(regByte))# ObjectIn(utStream regObjectStream = new ObjectIn(utStream( reg<rrayStream)# 5egi)trationIm(l reg= (5egi)trationIm(l) regObjectStream.rea+Object()# return reg# 8 el)e 7 t,row new $in+er>1ce(tion ()# 8 8 catc, (>1ce(tion )@e) 7 Sy)tem.out.(rintln('e1ce(tion '&)@e)# t,row new $in+er>1ce(tion ()# 8 %inally 7 try 7 r).clo)e()# ().clo)e()# con.clo)e()# 8 catc, (>1ce(tion ignore) 78 8 8 BLOBs and CLOBs: Storing large fields in a table with the other data is not necessarily the optimum place especially if the data has a variable size. One way to handle large, variable sized objects is with the Large Objects (LOs! type. LOs use a locator, essentially a pointer, in the database record that points to the real database field. "here are two types of LOs: inary Large Objects (LOs! and #haracter Large Objects (#LOs!. $hen you access a LO or #LO, the data is not copied to the client. "o retrieve the actual data from a result set, you have to retrieve the pointer with a call to BLOB blob=getBlob(1) or CLOB clob=getClob(1), and then retrieve the data with a call to blob.getBinaryStream() or clob.getBinaryStream(). Controlling Transactions y default, %&# statements are processed in full auto'commit mode. "his mode wor1s well for a single database *uery, but if an operation depends on several database statements that all have to complete successfully or the entire operation is cancelled, a finer transaction is needed. / description of transaction isolation levels is covered in more detail in #hapter 2: &ata and "ransaction (anagement. "o use transaction management in the %&# platform, you first need to disable the full auto'commit mode by calling: Connection con= getConnection()# con.)et<utoCommit(%al)e)# /t this point, you can either commit any following %&# statements or undo any updates by calling the Connection.rollbac: method. "he rollbac: call is commonly placed in the 3.ception handler, although it can be placed anywhere in the transaction flow. "his ne.t e.ample inserts an auction item and decrements the user4s balance. +f the balance is less than zero, the entire transaction is rolled bac1 and the auction item is removed. (ublic int in)ertItem(String )eller. String (a))wor+. String +e)cri(tion. int auction+ay). +ouble )tart(rice. String )ummary) 7 Connection con = null# int count=# +ouble balance=# java.)@l.;ate en++ate. )tart+ate# Statement )tmt=null# *re(are+Statement () = null# try 7 con=getConnection()# con.)et<utoCommit(%al)e)# )tmt= con.createStatement()# )tmt.e1ecute6uery( ')elect counter %rom auctionitem)')# 5e)ultSet r) = )tmt.get5e)ultSet()# i%(r).ne1t()) 7 count=r).getInt(1)# 8 Calen+ar currenttime=Calen+ar.getIn)tance()# java.util.;ate current+ate=currenttime.get9ime()# )tart+ate=new java.)@l.;ate( current+ate.get9ime())# currenttime.a++(Calen+ar.;<9>. auction+ay))# en++ate=new java.)@l.;ate(( currenttime.get9ime()).get9ime())# ()=con.(re(areStatement( 'in)ert into auctionitem)( i+. +e)cri(tion. )tart+ate. en++ate. )tart(rice. )ummary) value) (-.-.-.-.-.-)')# ().)etInt(1. count)# ().)etString(0. +e)cri(tion)# ().)et;ate(A. )tart+ate)# ().)et;ate(4. en++ate)# ().)et;ouble(!. )tart(rice)# ().)etString(". )ummary)# ().e1ecute2(+ate()# ().clo)e()# ()=con.(re(areStatement( 'u(+ate regi)tration )et balance=balance B.! w,ere t,eu)er= -')# ().)etString(1. )eller)# ().clo)e()# )tmt= con.createStatement()# )tmt.e1ecute6uery( ')elect balance %rom regi)tration w,ere t,eu)er=C'&)eller&'C')# r) = )tmt.get5e)ultSet()# i%(r).ne1t()) 7 balance=r).get;ouble(1)# 8 )tmt.clo)e()# i%(balance D) 7 con.rollbac:()# con.clo)e()# return (B1)# 8 )tmt= con.createStatement()# )tmt.e1ecute2(+ate( 'u(+ate auctionitem) )et counter=counter&1')# )tmt.clo)e()# con.commit()# con.clo)e()# return()# 8 catc,(S6L>1ce(tion e) 7 try 7 con.rollbac:()# con.clo)e()# )tmt.clo)e()# ().clo)e()# 8catc, (>1ce(tion ignore)78 8 return ()# 8 Escaping Characters "he %&# /5+ provides the e)ca(e 1eyword so you can specify the character you want to use to escape characters. 6or e.ample, if you want to use the percent sign (E! as the percent sign and not have it interpreted as the S7L wildcard used in S7L LI=> *ueries, you have to escape it with the escape character you specify with the e)ca(e 1eyword. "his ne.t statements shows how you would use the e)ca(e 1eyword to loo1 for the value 1E. )tmt.e1ecute6uery( ')elect ta1 %rom )ale) w,ere ta1 li:e C1FEC 7e)ca(e CFC8')# +f your program stores names and addresses to the database entered from the command line or by way of a user interface, the single *uotes (C! symbol might appear in the data. 5assing single *uotes directly into a S7L string causes problems when the S7L statement is parsed because S7L gives this symbol another meaning unless it is escaped. "o solve this problem, the following method escapes any C symbol found in the input line. "his method can be e.tended to escape any other characters such as commas . that the database or database driver might interpret another way. )tatic (ublic String e)ca(eLine(String )) 7 String retvalue = )# i% ().in+e1O% ('C') ?= B1 ) 7 StringBu%%er ,ol+ = new StringBu%%er()# c,ar c# %or(int i=# i D ).lengt,()# i&& ) 7 i% ((c=).c,ar<t(i)) == CFCC ) 7 ,ol+.a((en+ ('CC')# 8el)e 7 ,ol+.a((en+(c)# 8 8 retvalue = ,ol+.toString()# 8 return retvalue# 8 -owever, if you use a *re(are+Statement instead of a simple Statement, most of these escape problems go away. 6or e.ample, instead of this line with the escape se*uence: )tmt.e1ecute6uery( ')elect ta1 %rom )ale) w,ere ta1 li:e C1FEC 7e)ca(e CFC8')# 8ou could use this line: (re(are+)tmt = C.(re(areStatement( 'u(+ate ta1 )et ta1 = -')# Mapping Database Types /part from a few %&# types such as IG9>H>5 that are represented as an IG9>H>5 in most popular databases, you might find that the %&# type for a table column does not match the type as it is represented in the database. "his means calls to 5e)ultSet.getObject, *re(are+Statement.)etObject and CallableStatement.getObject() will very li1ely fail. 8our program can determine the database column type from the database meta data and use that information to chec1 the value before retrieving it. "his ne.t code chec1s that the value is in fact type IG9>H>5 before retrieving its value. int count=# Connection con=getConnection()# Statement )tmt= con.createStatement()# )tmt.e1ecute6uery( ')elect counter %rom auctionitem)')# 5e)ultSet r) = )tmt.get5e)ultSet()# i%(r).ne1t()) 7 i%(r).getIeta;ata().getColumn9y(e(1) == 9y(e).IG9>H>5) 7 Integer i=(Integer)r).getObject(1)# count=i.intJalue()# 8 8 r).clo)e()# Mapping Date types "he ;<9> type is where most mismatches occur. "his is because the java.util.;ate class represents both &ate and "ime, but S7L has the following three types to represent data and time information: / ;<9> type that represents the date only (92:;2:<<!. / 9II> type that specifies the time only (=;:92:><! / 9II>S9<I* that represents time value in nanoseconds. "hese three additional types are provided in the java.)@l pac1age as java.)@l.;ate, java.)@l.9ime and java.)@l.9ime)tam( and are all subclasses of java.util.;ate. "his means you can use convert java.util.;ate values to the type you need to be compatible with the database type. ote! "he 9ime)tam( class loses precision when it is converted to a java.util.;ate because java.util.;ate does not contain a nanosecond field, it is better to not convert a 9ime)tam(instance if the value will be written bac1 to the database. "his e.ample uses the java.)@l.;ate class to convert the java.util.;ate value returned by the call to Calen+ar.get9ime to a java.)@l.;ate. Calen+ar currenttime=Calen+ar.getIn)tance()# java.)@l.;ate )tart+ate= new java.)@l.;ate(( currenttime.get9ime()).get9ime())# 8ou can also use the java.te1t.Sim(le;ate$ormat class to do the conversion. "his e.ample uses the java.te1t.Sim(le;ate$ormat class to convert a java.util.;ate object to a java.)@l.;ate object: Sim(le;ate$ormat tem(late = new Sim(le;ate$ormat('yyyyBIIB++')# java.util.;ate en++ate = new java.util.;ate('1KA1KLL')# java.)@l.;ate )@l;ate = java.)@l.;ate.valueO%( tem(late.%ormat(en++ate))# +f you find a database date representation cannot be mapped to a %ava type with a call to getObject or get;ate, retrieve the value with a call to getString and format the string as a ;ate value using the Sim(le;ate$ormat class shown above. What is JServer and what is it used for? Oracle JServer Option is a Java Virtual Machine (Java VM) which runs within the Oracle database server's address space. Oracle also provides a JServer Accelerator to compile Java code natively. This speeds up the eecution o! Java code by eliminatin" interpreter overhead. #ac$ to top o! !ile How does one install the Oracle JServer Option? %ollow these steps to activate the Oracle JServer& JVM option' Ma$e sure your database is started with lar"e (ava)pool)si*e (+,-M) and shared)pool)si*e (+.-M) /0/T.O1A parameter values. 1un the 2O1A345)6OM5&(avavm&install&init(vm.s7l script !rom S8S AS S8S9#A to install the Oracle JServer Option on a database. :rant JAVA;S51<1/V to users that wants to use Java' S6LM H5<G9 N<J<2S>5*5IJ 9O SCO99# The rmjvm.sql script can be used to deinstall the JServer option !rom your database. %ollow the steps in the Oracle Mi"rations :uide to up"rade or down"rade the JServer option !rom one release to another. #ac$ to top o! !ile How does one load Java Source code into the database? ;se the =CREATE OR REPLACE JAVA SOURCE= command or =loadjava= utility. See this script !or an eample. 4oaded code can be viewed by selectin" !rom the ;S51)SO;135 view. #ac$ to top o! !ile Why does one need to publish Java in the database? <ublishin" Java classes on the database ma$es it visible on a S>4 and <4&S>4 level. /t is important to publish your code be!ore callin" it !rom S>4 statements or <4&S>4 code. 4oo$ at this eample' create or re(lace %unction ,ello ()tr varc,ar0) return varc,ar a) language java name COello.I)g(java.lang.String) return java.lang.StringC# K #ac$ to top o! !ile What is JDBC and what is it used for? J9#3 is a set o! classes and inter!aces written in Java to allow other Java pro"rams to send S>4 statements to a relational database mana"ement system. Oracle provides three cate"ories o! J9#3 drivers' J9#3 Thin 9river (0o local 0et? installation re7uired& handy !or applets) J9#3 O3/ !or writin" stand@alone Java applications J9#3 A<1# driver (de!ault connection) !or Java Stored <rocedures and 9atabase JS<'s. Oracle's JDBC Thin driver uses Java soc$ets to connect directly to Oracle. /t provides its own T3<&/< version o! Oracle's 0et? (S>4B0et) protocol. #ecause it is C--D JavaE this driver is plat!orm independent and can also run !rom a Feb #rowser (applets). Oracle's JDBC OC drivers uses Oracle O3/ (Oracle 3all /nter!ace) to interact with an Oracle database. 8ou must use a J9#3 O3/ driver appropriate to your Oracle client installation. The O3/ driver wor$s throu"h either S>4B0et or 0et?. J9#3 O3/G wor$s with an OracleG client. J9#3 O3/? wor$s with an Oracle? client. 5ither o! these client versions can access OracleG or Oracle? servers. The J9#3 O3/ drivers allow you to call the O3/ directly !rom JavaE thereby providin" a hi"h de"ree o! compatibility with a speci!ic Version o! Oracle. #ecause they use native methodsE they are plat!orm speci!ic. Oracle's JDBC !B"# driver is mainly used !or writin" Java stored proceduresE tri""ers and database JS<s. /t uses the de!ault& current database session and thus re7uires no additional database usernameE password or ;14. All three drivers support the same synta and A</'s. Oracle needs three drivers to support di!!erent deployment options. 4oo$in" at source codeE they will only di!!er in the way you connect to the database. 1ememberE you must use a J9#3 version that matches the version o! your Java 9evelopment Ait. #ac$ to top o! !ile How does one connect with the JDBC Thin Driver? The the J9#3 thin driver provides the only way to access Oracle !rom the Feb (applets). /t is smaller and !aster than the O3/ driversE and doesn't re7uire a pre@installed version o! the J9#3 drivers. im(ort java.)@l.P# cla)) +b<cce)) 7 (ublic )tatic voi+ main (String arg) 34) t,row) S6L>1ce(tion 7 ;riverIanager.regi)ter;river (new oracle.j+bc.+river.Oracle;river())# Connection conn = ;riverIanager.getConnection ('j+bc/oracle/t,in/Q@itBu@Bcbiw/1!0"/orcl'. ')cott'. 'tiger')# KK Qmac,ineGame/(ort/SI;. u)eri+. (a))wor+ Statement )tmt = conn.createStatement()# 5e)ultSet r)et = )tmt.e1ecute6uery(')elect B<GG>5 %rom SRS.JSTJ>5SIOG')# w,ile (r)et.ne1t()) Sy)tem.out.(rintln (r)et.getString(1))# KK *rint col 1 )tmt.clo)e()# 8 8 #ac$ to top o! !ile How does one connect with the JDBC OC Driver? One must have 0et? (S>4B0et) installed and wor$in" be!ore attemptin" to use one o! the O3/ drivers. im(ort java.)@l.P# cla)) +b<cce)) 7 (ublic )tatic voi+ main (String arg) 34) t,row) S6L>1ce(tion 7 try 7 Cla)).%orGame ('oracle.j+bc.+river.Oracle;river')# 8 catc, (Cla))Got$oun+>1ce(tion e) 7 e.(rintStac:9race()# 8 Connection conn = ;riverIanager.getConnection ('j+bc/oracle/ociU/Q@itBu@BcbiwSorcl'. ')cott'. 'tiger')# KK or ociV Q9GSGame)S>ntry. u)eri+. (a))wor+ Statement )tmt = conn.createStatement()# 5e)ultSet r)et = )tmt.e1ecute6uery(')elect B<GG>5 %rom SRS.JSTJ>5SIOG')# w,ile (r)et.ne1t()) Sy)tem.out.(rintln (r)et.getString(1))# KK *rint col 1 )tmt.clo)e()# 8 8 #ac$ to top o! !ile How does one connect with the JDBC !"#B Driver? One can obtain a handle to the de!ault or current connection (A<1# driver) by callin" the Oracle9river.de!ault3onenction() method. <lease note that you do not need to speci!y a database ;14E username or password as you are already connected to a database session. 1emember not to close the de!ault connection. 3losin" the de!ault connection mi"ht throw an eception in !uture releases o! Oracle. im(ort java.)@l.P# cla)) +b<cce)) 7 (ublic )tatic voi+ main (String arg) 34) t,row) S6L>1ce(tion 7 Connection conn = (new oracle.j+bc.+river.Oracle;river()).+e%aultConnection()# Statement )tmt = conn.createStatement()# 5e)ultSet r)et = )tmt.e1ecute6uery(')elect B<GG>5 %rom SRS.JSTJ>5SIOG')# w,ile (r)et.ne1t()) Sy)tem.out.(rintln (r)et.getString(1))# KK *rint col 1 )tmt.clo)e()# 8 8 #ac$ to top o! !ile Where can one $et %ore info about JDBC? 9ownload Sun's Java 9evelopers Ait and various other A</'s J9#3 :uide' :ettin" Started 9ownload Oracle's J9#3 9rivers The comp.lan".(ava %A> 4ist #ac$ to top o! !ile What is S&'J and what is it used for? S>4J is an A0S/ standard way o! codin" S>4 access in Java. /t provides a Java precompiler that translates S>4J call to J9#3 calls. The idea is similar to that o! other Oracle <recompilers. S>4J is more concise and thus easier to write than J9#3E and provides compile@time schema validation and synta chec$in" !or easier debu""in". S>4J reads input either !rom a B.S>4J !ileE or a Java source !ile in which S>4J statements are embedded. The S>4J precompiler translates the S>4J statements into their e7uivalent J9#3 calls. S>4J supports static S>4. #ac$ to top o! !ile How does one write S&'J pro$ra%s? See the Scripts and sample pro"rams section !or some S>4J eample pro"rams. #ac$ to top o! !ile How does one deploy S&'J pro$ra%s? ;se the s7l( compiler to compile your B.s7l( !iles to B.(ava and B.ser !iles. The B.ser !iles contain vendor speci!ic database code. Therea!ter one invo$es the (avac compiler to compile the .(ava !iles to B.class !iles. The B.class and B.ser !iles needs to be deployed. #ac$ to top o! !ile Where can one $et %ore info about S&'J? The S>4J Or"ani*ation Sun's /n!o#us 3ontrols #ac$ to top o! !ile What is JDeveloper and what is it used for? J9eveloper is the Oracle /95 (/nte"rated 9evelopment 5nvironment) !or developin" S>4J and J9#3 pro"ramsE appletsE stored proceduresE 5J#'sE JS<'s etc. J9eveloper are etremely resource hun"ry and re7uires a bi" wor$station. 6oweverE it provides an etremely productive environment !or Java 9evelopers. #ac$ to top o! !ile How does one set runti%e para%eter in JDeveloper? 0avi"ate to Project |--> Project Propertes... |--> R!"#$e%!& and enter !ield parameters. These parameters will be pic$ed up when you eecute a Java pro"ram !rom J9eveloper. (ublic )tatic voi+ main(String[] args) 7 ... #ac$ to top o! !ile What is nfoBus D(C and what is it used for? /n!o#us 9A3 (9ata Aware 3ontrols) is a standard Java etension used in J9eveloper to create data aware !orms. /t replaced the J#34 inter!ace that were used in J9eveloper VC and V,. More in!o about /n!obus are available !rom the !ollowin" ;14' (ava.sun.com&beans&in!obus To use /n!o#us 9A3E import (ava.in!obus.BH into your Java pro"ram. #ac$ to top o! !ile What is a JS" and what is it used for? Java Server <a"es (JS<) is a plat!orm independent presentation layer technolo"y that comes with S;0's J,55 plat!orm. JS<s are normal 6TM4 pa"es with Java code pieces embedded in them. JS< pa"es are saved to B.(sp !iles. A JS< compiler is used in the bac$"round to "enerate a Servlet !rom the JS< pa"e. #ac$ to top o! !ile What is the difference between (S" and JS"? Active Server <a"es (AS<) is a Microso!t standardE which is easier to develop than Java Server <a"es (JS<). 6owever AS< is a proprietary technolo"y and is less !leible than JS<. %or more in!ormation about AS<E see the Oracle AS< %A>. #ac$ to top o! !ile How does one invo)e a JS"? A JS< "ets invo$ed when you call a B.(sp !ile !rom your Feb Server li$e you would call a normal B.html !ile. Obviously your web server need to support JS< pa"es and must be con!i"ured properly to handle them. #ac$ to top o! !ile How does a JS" $ets e*ecuted? The !irst time you call a JS<E a servlet (B.(ava) will be created and compiled to a .class !ile. The class !ile is then eecuted on the server. Output produced by the servlet is returned to the web browser. Output will typically be 6TM4 or IM4 code. #ac$ to top o! !ile How does one write a JS" pa$e? 8ou can use Oracle J9eveloper to create JS< pa"es. Alternatively you can open a standard tet !ile and code the re7uired 6TM4 and Java manually. 4oo$ at this eample' DO9ILM DBO;RM DE out.(rintln('Oello Worl+')# EM D*M 9o+ay i)/ DE= new java.util.;ate() EM D*M *age generate+ wit,/ DE= t,i).getServeleteIn%o() EM D*M #ac$ to top o! !ile What is a Java Stored "rocedure+ Tri$$er? A Java Stored <rocedure is a procedure coded in Java (as opposed to <4&S>4) and stored in the Oracle database. Java Stored procedures are eecuted by the database JVM in database memory space. Java Stored <rocedures can be developed in J9#3 or S>4J. /nter!acin" between <4&S>4 and Java are etremely easy. <lease note that Java Stored procedures are by de!ault eecuted with invo$ers ri"hts. <4&S>4 procedures are by de!ault eecuted with de!ines ri"hts. 0ote' JS< is Java Server <a"es and 0OT Java Stored <rocedures. #ac$ to top o! !ile How does one write a Java Stored "rocedure? Java Stored <rocedures must comply with the !ollowin" rules' 0o constructor method is needed Variables and methods must be declared static ;se the de!ault database connection (no userid& password re7uiredE run in session) 9eclare output variables as arrays (ublic static voi+ get>m(In%o(int em(no. String[] em(Game. int[] )alary) 7 #ac$ to top o! !ile How does on load a Java Stored "rocedure into the database? 3reate a deployment pro!ile !rom J9eveloper or use the load(ava command line utility. #ac$ to top o! !ile How does on drop a Java Stored "rocedure fro% the database? S>4B<lus' drop (ava class ...& drop pac$a"e ... (drop the wrapper) drop(ava utility' drop(ava @u scott&ti"er my<ac$a"e.my3lass #ac$ to top o! !ile How does on call+e*ecute a Java Stored "rocedure? %rom S>4B<lus' ;se eecute or call %rom J9#3' ;se the 3allableStatement ob(ect %rom S>4J' Js7l K call ...L e"' Js7l K call A3M5.#5:/0150TA4('in member/9E 'in employee/9E 'outE ...) LH import (ava.s7l.BH public class 3reate3o!!ees K public static void main(Strin" ar"sMN) K Strin" url O =(dbc'mySubprotocol'my9ataSource=H 3onnection conH Strin" createStrin"H createStrin" O =create table 3O%%55S = P =(3O%)0AM5 VA136A1(Q,)E = P =S;<)/9 /0T5:51E = P =<1/35 %4OATE = P =SA45S /0T5:51E = P =TOTA4 /0T5:51)=H Statement stmtH try K 3lass.!or0ame(=my9river.3lass0ame=)H L catch((ava.lan".3lass0ot%ound5ception e) K System.err.print(=3lass0ot%ound5ception' =)H System.err.println(e."etMessa"e())H L try K con O 9riverMana"er."et3onnection(urlE =my4o"in=E =my<assword=)H stmt O con.createStatement()H stmt.eecute;pdate(createStrin")H stmt.close()H con.close()H L catch(S>45ception e) K System.err.println(=S>45ception' = P e."etMessa"e())H L L L OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO
Microsoft Access Guide to Success: From Fundamentals to Mastery in Crafting Databases, Optimizing Tasks, & Making Unparalleled Impressions [III EDITION]