Java & PL/SQL: For Oracle RDBMS
Java & PL/SQL: For Oracle RDBMS
Java & PL/SQL: For Oracle RDBMS
copyright 2004
INTRODUCTION
Joel
A. Thompson
15 years of industry experience
Consultant: Architecture, Software
Engineering and Project Manager
Java and Oracle expert
copyright 200
OVERVIEW
Basics
of PLSQL
Optimizing RDBMS Calls from JAVA
Return Values & Cursors
Logic processing on Server, ARRAY inserts
And more
Examples
WRAP
UP / Q&A
copyright 200
copyright 200
Client Requirement
Copy the $ORACLE_HOME/jdbc/lib/classes12.jar to your
client side's CLASSPATH.
Connect string example (thin driver) requires no client side
libraries: jdbc:oracle:thin:joel/welcome@localhost:1521:UCDBA
copyright 200
copyright 200
What is PL/SQL?
A programming
language
If/then/else
Loops
Function calls
Transactional
Procedural
Feature
rich
Performance Gain
Oracle only
copyright 200
copyright 200
ADHOC
Send the PL/SQL block of code from the client java
program to the server for processing.
FUNCTION
Client Side calls a PL/SQL function in Oracle.
PL/SQL is already compiled and loaded in Oracle.
Function will return a value
PROCEDURE
Client calls a PL/SQL procedure
Similar to function, but does not return values.
copyright 200
copyright 200
10
copyright 200
11
return;
}
copyright 200
12
copyright 200
13
return info;
}
copyright 200
14
3
4
ps =connection.prepareStatement(sbSQL.toString());
int indx=1;
ps.setString(indx++,SSNO);
int rettype=Types.INTEGER;
ps.registerOutParameter(indx++,rettype);
rettype=Types.VARCHAR;
ps.registerOutParameter(indx++,rettype);
ps.executeUpdate();
l_sError=ps.getString(2);
if(l_sError!=null)
{
System.err.println("PL/SQL Error: " + l_sError);
return;
}else
{
ret=ps.getInt(1);
System.out.println("New USERID: " + ret);
}
copyright 200
15
Analysis of Example 4
BEGIN
END;
copyright 200
16
Analysis of Example 4
17
Analysis of Example 4
copyright 200
18
Analysis of Example 4
copyright 200
19
offs?
20
copyright 200
21
copyright 200
22
copyright 200
23
copyright 200
24
Example 5 PLSQL
copyright 200
25
copyright 200
26
Example 6 objective
copyright 200
27
copyright 200
28
BEGIN
into id;
commit;
EXCEPTION WHEN OTHERS then
rollback;
END;
END;
/
copyright 200
29
PreparedStatement ps =null;
ArrayDescriptor desc = ArrayDescriptor.createDescriptor("JOEL.STR_VARRAY", m_Conn);
String sCar="";
String cars[]=new String[10];
for(int i=0;i<10;i++)
{
sCar="carX"+i;
// CONTRIVE A NAME of a CAR
cars[i]=new String(sCar);
}
ARRAY array3 = new ARRAY (desc, m_Conn, cars);
String sql=new String("{call api_person_pkg.storePersonCar('joelt',?) }");
ps= m_Conn.prepareStatement(sql);
// Set the values to insert
((oracle.jdbc.driver.OraclePreparedStatement)ps).setARRAY(1, array3);
// Insert the new row
ps.executeUpdate();
m_Conn.commit();
copyright 200
30
copyright 200
31
Standards
JDBC standards
Other issues (dates, functionsetc.)
Portability from schema-to-schema
abstracting calls to database with PL/SQL
layer
copyright 200
32
WRAP-UP
QUESTIONS
and Answers
MORE INFORMATION:
Contact: [email protected]
Or call: 530-888-6248 x205
copyright 200
33