Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

PL/SQL - calling java class in OracleDB and establish connection to that DB

Rado_mirJun 3 2013 — edited Jun 3 2013
Hello Oracle Users. I have a question. I`m trying to deploy java class into Oracle db. These class functionality is to establish connect to the same Oracle db. I know that is wrong but i really need to do that. Is that possible?? Maybe i will show some example and what i have done.

Java Class

public class test {

public static String say(String arg)
{
Connection connection = null;
try {

Class.forName("oracle.jdbc.driver.OracleDriver");

} catch (ClassNotFoundException e) {

System.out.println("error with driver");
e.printStackTrace();

}

try {

connection = DriverManager.getConnection(
"jdbc:oracle:thin:@localhost:1521:OracleDB", "system",
"adminroot");
Statement stmt = connection.createStatement();
ResultSet rset = stmt.executeQuery("Create table test(a number)");

} catch (SQLException e) {

System.out.println("connection error");
e.printStackTrace();


}
return arg;

}
}
That test class i have compiled, tested and deployed on my Oracle DB with loadjava command.

Then i wrote a PL/SQL function to call java test class.

create or replace function trythis
(id VARCHAR2)
return VARCHAR2
as language java
name 'project1.test.say(java.lang.String)
return java.lang.String';

Then i get some GRANT errors ( i have handle with this )

When i`m trying to call --> Select trythis('test') from dual; function is returning text but i can`t find new table test. Could someone help me with that?? I was thinking problem is with ojdbc drivers and i have used loadjava to deploy that drivers into oracle but that won`t help.

Best regards
Radomir

PS. Sorry for my English.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 1 2013
Added on Jun 3 2013
4 comments
245 views