如何使用 Java 语言将 SOAP 转换为 REST?
package net.weather;
import java.sql.*;
import javax.jws.WebService;
@WebService
public class ProjectFinalWS{
Connection con;
Statement st;
ResultSet rs;
String res;
public void connectDB()
{
String url ="jdbc:mysql://localhost:3306/";
String dbName ="project";
String driver = "com.mysql.jdbc.Driver";
String userName = "root";
String password = "root";
try
{
Class.forName(driver).newInstance();
con = DriverManager.getConnection(url+dbName,userName,password);
}catch(Exception e){}
}
public float getMaxTemp(String city)
{ float mxtemp=0;
connectDB();
try{
st=con.createStatement();
rs=st.executeQuery("select maxtemp from weather where city='"+city+"'");
rs.next();
mxtemp=rs.getFloat(1);
st.close();
con.close();
}
catch(Exception e){}
return mxtemp;
}
public float getMinTemp(String city)
{ float mntemp=0;
connectDB();
try{
st=con.createStatement();
rs=st.executeQuery("select mintemp from weather where city='"+city+"'");
rs.next();
mntemp=rs.getFloat(1);
st.close();
con.close();
}
catch(Exception e){}
return mntemp;
}
public float getHumidity(String city)
{ float humidity=0;
connectDB();
try{
st=con.createStatement();
rs=st.executeQuery("select humidity from weather where
city='"+city+"'");
rs.next();
humidity=rs.getFloat(1);
st.close();
con.close();
}
catch(Exception e){}
return humidity;
}
}