0

正如标题所说,我有数字站点 ID,我需要一种方法来获取相应的 GlobalId。

我知道有火柴的桌子

https://developer.ebay.com/DevZone/merchandising/docs/CallRef/Enums/GlobalIdList.html

https://developer.ebay.com/DevZone/merchandising/docs/Concepts/SiteIDToGlobalID.html

但我需要一种编程方式来做到这一点。

4

1 回答 1

1

你的三个选择:

哈希映射实现

 import java.util.HashMap;
 public class Mappings{

 public static void main(String []args){

    HashMap myMap = new HashMap<Integer, String>();
    myMap.put(0, "EBAY-US");
    myMap.put(2, "EBAY-ENCA");
    myMap.put(3, "EBAY-GB");
    myMap.put(15, "EBAY-AU");
    //...

    System.out.println("Given ID 15, it's corresponding Global ID is: " + myMap.get(15));

   }
}

SQL 表实现

 //STEP 1. Import required packages
 import java.sql.*;

 public class JDBCExample {
    // JDBC driver name and database URL
    static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";  
    static final String DB_URL = "jdbc:mysql://localhost/STUDENTS";

    //  Database credentials
    static final String USER = "username";
    static final String PASS = "password";

    public static void main(String[] args) {
    Connection conn = null;
    Statement stmt = null;
    try{
       //STEP 2: Register JDBC driver
       Class.forName("com.mysql.jdbc.Driver");

       //STEP 3: Open a connection
       System.out.println("Connecting to a selected database...");
       conn = DriverManager.getConnection(DB_URL, USER, PASS);
       System.out.println("Connected database successfully...");

       //STEP 4: Execute a query
       System.out.println("Inserting records into the table...");
       stmt = conn.createStatement();

       String sql = "INSERT INTO Mappings " +
               "VALUES (0, 'EBAY-US')";
       stmt.executeUpdate(sql);

       sql = "INSERT INTO Mappings " +
               "VALUES (2, 'EBAY-ENCA')";
       stmt.executeUpdate(sql);

       sql = "INSERT INTO Mappings " +
               "VALUES (3, 'EBAY-GB')";
       stmt.executeUpdate(sql);

       sql = "INSERT INTO Mappings " +
               "VALUES (15, 'EBAY-AU')";
       stmt.executeUpdate(sql);

       System.out.println("Inserted records into the table...");



       sql = "SELECT siteID, globalID FROM Mappings";

       ResultSet rs = stmt.executeQuery(sql);

     //STEP 5: Extract data from result set
       while(rs.next()){
          //Retrieve by column name
            int siteId  = rs.getInt("siteID");
            int globalId = rs.getInt("globalID");

            //Display values
            System.out.print("siteId: " + siteId);
            System.out.print(", globalId: " + globalId);

        }

    rs.close();
    }catch(SQLException se){
       //Handle errors for JDBC
       se.printStackTrace();
    }catch(Exception e){
       //Handle errors for Class.forName
       e.printStackTrace();
    }finally{
       //finally block used to close resources
       try{
          if(stmt!=null)
             conn.close();
       }catch(SQLException se){
       }// do nothing
       try{
          if(conn!=null)
             conn.close();
       }catch(SQLException se){
          se.printStackTrace();
       }//end finally try
    }//end try
    System.out.println("Goodbye!");
 }//end main
 }//end JDBCExample

和服实施

如果您不想为站点 ID <=> 全局 ID 映射提供本地存储,如 techcrunch 文章中所述,“ Kimono 是一种更智能的 Web Scraper,可让您“API 化”Web,无需代码, “:

 With Kimono, the end goal is to simplify data extraction so that anyone can manage it. 
 Then Kimono’s learning algorithm will build a data model involving the items you’ve
 selected.

正如和服的网站所提到的:

 Turn websites into structured APIs from your browser in seconds.
于 2014-10-15T17:25:24.213 回答