Another way to use the URL class is to download a document from an HTTP URL. Before you start, your client must connect to a Web server. In the client code, you:
Create a URL object.
Create an InputStream object from the URL object.
Use read on the InputStream object to read in the document.
To use the following code sample, you must:
Read the entire document into Adaptive Server memory.
Create a new InputStream on the document in Adaptive Server memory.
For example:
public static InputStream url_test() throws Exception { URL u = new URL(“http://www.xxxxxx.com/”); Reader in = new InputStreamReader(u.openStream())); int n=0, off; char c[]=new char[50000];
for(off=0;(off<c.length-512) &&((n=in.read(c,off,512))!=-1;off+=n) for(off=0; off < c.length; off ++) { b[off]=(byte)c[off]; in.close(); ByteArrayInputStream test = new ByteArrayInputStream(b,0,off); return (InputStream) test}
After you create the new InputStream class, you can install this class and use it to read a text file into the database, inserting data into a table, as in the following example.
create table t (cl text)
insert into t values ( URLprocess.readURL)
select datalength(cl) from
--------------
34136