Example #1
0
 @Override
 @SuppressWarnings("rawtypes")
 public void prepare(Map stormConf, TopologyContext context) {
   seprator = PropertyUtil.getProperty("seprator");
   try {
     conn = DBManager.getConnection();
     String selectSql = "SELECT * FROM " + tableName;
     insertSql = "INSERT INTO " + tableName;
     PreparedStatement pstmt = conn.prepareStatement(selectSql);
     ResultSet rs = pstmt.executeQuery();
     ResultSetMetaData metaData = rs.getMetaData();
     int columnCount = metaData.getColumnCount();
     String fields = " (";
     String vals = " (";
     for (int i = 1; i <= columnCount; i++) {
       String columnName = metaData.getColumnName(i);
       if (i < columnCount) {
         fields += columnName + ", ";
         vals += "?, ";
       } else {
         fields += columnName + ")";
         vals += "?) ";
       }
     }
     insertSql += (fields + " VALUES " + vals);
   } catch (SQLException e) {
     log.error("获取元数据失败", e);
     throw new RuntimeException("获取元数据失败", e);
   }
 }
Example #2
0
 @Override
 public void cleanup() {
   DBManager.closeConnection(conn);
 }