Oracle Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesOracle Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 9th, 2004, 09:11 AM
cheesyhoward cheesyhoward is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 6 cheesyhoward User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 15 sec
Reputation Power: 0
storing java variables in SQL / pipelined function

I have a java function which is called from within a select statement.

select latitude, longitude from scatter where latlong(latitude, longitude)=1;

For each latitude and longitude field in the scatter table the values are input to the function latlong which compares them to reference latitude longitude points. If the compared points are >2 from the ref points then a 1 is returned and the row is included in the output from the select statement.

The current code is…

import java.io.*;
import java.sql.*;
import oracle.jdbc.*;
import oracle.sql.*;

public class latLong
{
public static String compLatLong (String latitudeS, String longitudeS) throws SQLException
{
Connection conn = DriverManager.getConnection("jdbc:default:connection:");

// these need to be set from the obtained sql variables
// some how need to load them in
int reflat=0;
int reflong=0;

// assuming values have been loaded in

// check to see if the variables do not have a value
if ((reflat==0)||(reflong==0))
{
// must be first row in scatter table
// set values of
reflat=Integer.parseInt(latitudeS.trim());
reflong=Integer.parseInt(longitudeS.trim());
// write out sql variables here
return (new String("1"));
}
else
{
// compare the lat / long points
int latitude=0;
int longitude=0;
latitude = Integer.parseInt(latitudeS.trim());
longitude = Integer.parseInt(longitudeS.trim());
int compLong=latitude-reflat;
int compLat=longitude-reflong;
compLong=Math.abs(compLong);
compLat=Math.abs(compLat);

// check the distance between the 2 points

if ((compLong<=2)&&(compLat<=2))
return (new String("0"));

else
// update sql variables here
return (new String("1"));
}
}

}

I would like to know how to modify the code so that the reference latitude and longitude points are obtained from sql (session??) variables which are updated each time the function is executed.

So when the function is first called from the select statement it checks to see if the lat and long sql variables exist. If they do not it creates them and assigns them the current values of latitude and longitude that were passed to the function from the scatter table. It will then return 1 so that the first row from the table is always included in the results table.

For the second row in the scatter table the function will load the sql variables lat and long into the java code that were defined above and compare them to the current values of latitude and longitude that were passed to the function from the scatter table. If the difference between them is <=2 then the function returns 0 and the values of lat / long need not be updated. However if the difference is >2 the function should update the sql variables with the current latitude and longitude and them return 1.

This then repeats for all rows in the scatter table producing a results table that contains latitude and longitude points that are >2 units apart.

Would a pipelined function work better? How would I create one that is suitable for my selection objective?

Thanks Howard

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesOracle Development > storing java variables in SQL / pipelined function

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap