Database Reference
In-Depth Information
Listing 4-1. MyApp4 and f_get_oracle_time
SET ROLE appsec_role;
CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED myapp4 AS
package pkg4;
import java.sql.*;
import oracle.jdbc.driver.OracleDriver;
public class MyApp4 {
public static String getOracleTime() {
String timeString = null;
Statement stmt = null;
try {
//Class.forName( "oracle.jdbc.driver.OracleDriver" );
//new oracle.jdbc.OracleDriver();
//Connection conn = new OracleDriver().defaultConnection();
Connection conn = DriverManager.getConnection("jdbc:default:connection");
stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery( "select sysdate from dual" );
if( rs.next() ) {
timeString = rs.getString(1);
}
} catch( Exception x ) {
timeString = x.toString();
} finally {
try {
if( stmt != null ) stmt.close();
} catch( Exception y ) {}
}
return timeString;
}
}
/
CREATE OR REPLACE FUNCTION f_get_oracle_time
RETURN VARCHAR2
AS LANGUAGE JAVA
NAME 'pkg4.MyApp4.getOracleTime() return java.lang.String';
/
Note The code in Listing 4-1 can be found in the file named Chapter4/AppSec.sql.
I want to point out one thing about this example code before we go any further. I know I said that
packages, like pkg4 in our example class MyApp4 , are coordinated with directories, but there is no pkg4
directory. I also said that there is always one public class defined in each *.java file with the class having
 
Search WWH ::




Custom Search