Hello .
I am trying to return multiple values from a method and i am unable to dothat.
Can anybody can help me in this regard.
The following is the Method i have.
Code:
public double getDistance(String City1 , String City2){
double lat1=0.0, lat2=0.0, long1=0.0, long2=0.0;
ResultSet rs = null;
Connection conn = null;
MakeConnection oMakeConnection = new MakeConnection();
conn = oMakeConnection.getConnection();
String sql = null;
sql = "SELECT LATITUDE, LONGITUDE from zipcodes WHERE city = ?";
java.sql.PreparedStatement pstmt = null;
try {
pstmt = conn.prepareStatement(sql);
} catch (SQLException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
try {
pstmt.setString(1,City1);
} catch (SQLException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
try {
rs=pstmt.executeQuery();
} catch (SQLException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
try {
if(rs.next())
{
long1 = rs.getDouble("longitude");
lat1 = rs.getDouble("latitude");
}
} catch (SQLException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
String sql1 = null;
sql1 = "SELECT LATITUDE,LONGITUDE from zipcodes WHERE city = ? ";
pstmt = null;
try {
pstmt = conn.prepareStatement(sql);
} catch (SQLException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
try {
pstmt.setString(1,City2);
} catch (SQLException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
try {
rs=pstmt.executeQuery();
} catch (SQLException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
try {
if(rs.next())
{
long2 = rs.getDouble("longitude");
lat2 = rs.getDouble("latitude");
}
} catch (SQLException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
return long1;
return long2;
return lat1;
return lat2;
}
I cant return long1, long2, lat1, lat2.
I want all the values. How can i do that ??
Waiting for the reply.
Thanks in Advance.