|
SQLJ example classes for Sybase ASE 12.5 |
||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--SQLJExamples
A class with methods to illustrate SQLJ facilities.
Constructor Summary | |
SQLJExamples()
|
Method Summary | |
static void |
bestTwoEmps(java.lang.String[] n1,
java.lang.String[] id1,
java.math.BigDecimal[] s1,
int[] r1,
java.lang.String[] n2,
java.lang.String[] id2,
java.math.BigDecimal[] s2,
int[] r2,
int regionParm)
A method that provides the column data for the top two employees whose region is above a given value. |
static void |
correctStates(java.lang.String oldSpelling,
java.lang.String newSpelling)
A method that updates the "salesemp" table to correct the spelling of a given state. |
static java.lang.String |
job(int jc)
A method that returns the job name for a given job code. |
static void |
orderedEmps(int regionParm,
java.sql.ResultSet[] rs)
An example method that returns a result set. |
static int |
region(java.lang.String s)
A method that returns a code for the geographic region of a given state. |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
Constructor Detail |
public SQLJExamples()
Method Detail |
public static int region(java.lang.String s) throws java.sql.SQLException
This method is intended for use with an SQLJ create function such as the following:
create function regionof(state char(20)) returns integer language java parameter style java external name 'Routines1.region(java.lang.String)'
That SQLJ function "regionof" would be called in SQL as follows:
select name, regionof(state) as region from salesemps where regionof(state)=3
s
- the given state abbreviationpublic static void correctStates(java.lang.String oldSpelling, java.lang.String newSpelling) throws java.sql.SQLException
This method is intended for use with an SQLJ create procedure such as the following:
create procedure correctstates(old char(20), notold char(20)) modifies sql data language java parameter style java external name 'Routines1.correctStates(java.lang.String java.lang.String)'
That SQLJ procedure 'correctstates' would be called in SQL as follows:
execute correctstates 'GEO', 'GA'
oldSpelling
- the incorrect spelling, e.g. "Calif"newSpelling
- the correct spelling, e.g. "CA"public static void bestTwoEmps(java.lang.String[] n1, java.lang.String[] id1, java.math.BigDecimal[] s1, int[] r1, java.lang.String[] n2, java.lang.String[] id2, java.math.BigDecimal[] s2, int[] r2, int regionParm) throws java.sql.SQLException
The method is intended for an SQLJ create procedure such as the following:
create procedure best2 (out n1 varchar(50), out id1 varchar(5), out s1 decimal(6,2), out r1 integer, out n2 varchar(50), out id2 varchar(50), out r2 integer, out s2 decimal(6,2), in region integer) language java parameter style java external name 'Routines2.bestTwoEmps(java.lang.String[], java.lang.String[], int[], java.math.BigDecimal[], java.lang.String[], java.lang.String[], int[], java.math.BigDecimal[], int)'
That SQLJ procedure "best2" would be called in SQL as follows:
declare @n1 varchar(50), @id1 varchar(5),
n1
- a string array for the first output nameid1
- a string array for the first output idr1
- a string array for the first output regions1
- a string array for the first output salesn2
- a string array for the second output nameid2
- a string array for the second output idr2
- a string array for the second output regions2
- a string array for the second output salesregionParm
- an int for the given regionpublic static void orderedEmps(int regionParm, java.sql.ResultSet[] rs) throws java.sql.SQLException
This method is intended for an SQLJ create procedure such as the following:
create procedure rankedemps(region integer) dynamic result sets 1 language java parameter style java external name 'Routines3.orderedEmps(int)'
That SQLJ procedure "rankedemps" would be called as a stored procedure by an SQL client. For example, a Java client such as the following:
java.sql.CallableStatement stmt = conn.prepareCall({call rankedemps(?)}); stmt.setInt(1,3); ResultSet rs = stmt.executeQuery(); while (rs.next()) { String name = rs.getString(1); int.region = rs.getInt(2); BigDecimal sales = rs.get.BigDecimal(3); System.out.print(Name = + name); System.out.print(Region = + region); System.out.print(Sales = + sales); System.out.printIn(): }
The main method of the Java class CallRankedEmps contains such a call of "rankedemps".
int
- an int with a region valuers
- the result set that will be returned on the SQLJ callpublic static java.lang.String job(int jc) throws java.sql.SQLException
This method is intended to illustrate the handling of nulls with the SQLJ null on null input clause. You would define an SQLJ function on this method, as follows:
create function jobof22(jc integer) returns varchar(20) returns null on null input language java parameter style java external name 'Routines5.job2(int)'
A call of the SQLJ "job22" function will implicitly return null (without calling "Routines5.job2" if the parameter value is null.
jc
- an int with the given job code
|
SQLJ example classes for Sybase ASE 12.5 |
||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |