0

我有一个 Java Webservice 代码。目前我在本地主机上运行它。当我在另一台服务器(使用静态 IP)上运行它时应该进行哪些更改。

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.PreparedStatement;

public class RetailerWS {
 public String customerData(){
  String customerInfo = "";
  try{
  Class.forName("com.mysql.jdbc.Driver");
  Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/retailer","root","chathura");
  //Find customer information where the customer ID is maximum
  PreparedStatement statement =  con.prepareStatement("SELECT * FROM customers WHERE C_ID = (SELECT MAX(C_ID) FROM customers)");
  ResultSet result = statement.executeQuery();

   while(result.next()){
    customerInfo = customerInfo + result.getString("name") + "&" + result.getString("C_ID") + "&"+result.getString("address") + "&"+result.getString("email");
  //Here "&"s are added to the return string. This is help to split the string in Android application
   }
  }

  catch(Exception exc){
   System.out.println(exc.getMessage());
   }

  return customerInfo;
  }

}
4

1 回答 1

0

如果数据库也托管在同一台服务器上,则无需进行任何更改。如果 DB 在其他服务器上,则更改此行:

 Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/retailer","root","chathura");

拥有您的数据库服务器的 ip/地址或主机名。

您的 Web 服务客户端需要使用您托管 Web 服务的新服务器的地址来调用其方法。

于 2013-10-09T06:39:06.170 回答