Skip to Main Content

Java and JavaScript in the Database

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!

Java function returning stream convert to clob

769226May 8 2010 — edited May 9 2010
Hello

I have a java class

package html;

import java.io.ByteArrayOutputStream;

import java.net.URL;
import java.net.Proxy;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.StringWriter;

import org.w3c.tidy.*;


public class Client {
//private static final String driver_class = "oracle.jdbc.driver.OracleDriver";

public static void setProxy(String host, Integer port){
System.setProperty("http.proxyHost", host);
System.setProperty("http.proxyPOrt", port.toString());
}

public static void main(String[] args){
setProxy("192.168.0.191", 3128);

try{
System.out.println(getSite2("http://www.scoach.ch/"));
} catch (Exception e){
e.printStackTrace();
}
}

public static OutputStream getSite(String sourceUrl) throws Exception {
URL url = new URL(sourceUrl);
InputStream is = url.openStream();
OutputStream os = new ByteArrayOutputStream();

Tidy tidy = new Tidy();
tidy.setQuiet(true);
tidy.setShowWarnings(false);
tidy.setShowErrors(0);
tidy.parse(is, os);

return os;
}

public static String getSite2(String sourceUrl) throws Exception {
URL url = new URL(sourceUrl);
InputStream is = url.openStream();
StringWriter os = new StringWriter();

Tidy tidy = new Tidy();
tidy.setQuiet(true);
tidy.setShowWarnings(false);
tidy.setShowErrors(0);
tidy.parse(is, os);

return os.toString();
}
}

and the wrapper classes:

create or replace procedure set_proxy(proxy IN varchar2, port IN number) AS LANGUAGE JAVA
NAME 'html.Client.setProxy(java.lang.String, java.lang.String)';
/

create or replace function get_site2(site IN varchar2) RETURN CLOB AS LANGUAGE JAVA
NAME 'html.Client.getSite(java.lang.String) return java.lang.String';
/

create or replace function get_site(site IN varchar2) RETURN CLOB AS LANGUAGE JAVA
NAME 'html.Client.getSite(java.lang.String) return java.io.OutputStream';
/


But String and Stream seems not to be compatible to CLOB ... I have found a lot of JDBC samples on the web, but I could not figure out how to use in a java function without inserting into somewhere. What would be the correct way to do this - sorry for the noob question .. I did trial and error for a long time ...

Thanks
Christian Maier
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 6 2010
Added on May 8 2010
4 comments
2,903 views