mysql 字段批改

  • 内容
  • 评论
  • 相关

mysql 字段修改

 public static void main(String[] args) {         String filePath = "C://Users//li-ningning//Desktop//fnTable.xls.xls"; //        filePath = "C://Users//li-ningning//Desktop//master_data_fncrm.xls";         File file = new File(filePath);         try {             FileInputStream in = new FileInputStream(file);             HSSFWorkbook wb = new HSSFWorkbook(in);             // /获取第一张Sheet表             HSSFSheet st = wb.getSheetAt(0);             for (int i = 0; i <= st.getLastRowNum(); i++) {                 String sql = "alter table ";                 HSSFRow row = st.getRow(i);                 if (row != null) {                     String tableName = toString((HSSFCell) row                             .getCell((short) 0));                     String column = toString((HSSFCell) row.getCell((short) 1));                     String length = toString((HSSFCell) row.getCell((short) 3));                     int value = Integer.parseInt(length);                     sql += tableName;                     sql += " modify ";                     sql += column;                     if (value <= 50) {                         sql += "  varchar(50)";                     } else if (value <= 100) {                         sql += "  varchar(100)";                     } else if (value <= 150) {                         sql += "  varchar(150)";                     } else if (value <= 200) {                         sql += "  varchar(200)";                     } else if (value <= 250) {                         sql += "  varchar(250)";                     } else if (value <= 300) {                         sql += "  varchar(300)";                     } else if (value < 500) {                         sql += "  varchar(500)";                     }                     sql += ";";                     String executeSql = sql;                     System.out.println(executeSql);                     sql = "";                 }             }         } catch (FileNotFoundException e) {             // TODO Auto-generated catch block             e.printStackTrace();         } catch (IOException e) {             // TODO Auto-generated catch block             e.printStackTrace();         } catch (Exception e) {             e.printStackTrace();         }     }      public static String toString(HSSFCell cell) {         String value = "";         if (cell == null) {             return value;         }         cell.setEncoding(HSSFCell.ENCODING_UTF_16);         switch (cell.getCellType()) {         case HSSFCell.CELL_TYPE_STRING:             value = cell.getStringCellValue().toString();             break;         case HSSFCell.CELL_TYPE_NUMERIC:             if (HSSFDateUtil.isCellDateFormatted(cell)) {                 Date date = cell.getDateCellValue();                 if (date != null) {                     value = new SimpleDateFormat("yyyy-MM-dd").format(date);                 } else {                     value = "";                 }             } else {                 value = new DecimalFormat("0").format(cell                         .getNumericCellValue());             }             break;         case HSSFCell.CELL_TYPE_FORMULA:             // 导入时如果为公式生成的数据则无值             if (!cell.getStringCellValue().equals("")) {                 value = cell.getStringCellValue();             } else {                 value = cell.getNumericCellValue() + "";             }             break;         case HSSFCell.CELL_TYPE_BLANK:             break;         case HSSFCell.CELL_TYPE_ERROR:             value = "";             break;         case HSSFCell.CELL_TYPE_BOOLEAN:             value = (cell.getBooleanCellValue() ? "YES" : "NO");             break;         default:             value = "";         }         return value.trim();     }

欢迎大家阅读《mysql 字段批改》,跪求各位点评,by 搞代码

 

原创文章,转载请注明: 转载自搞代码

本文链接地址: mysql 字段批改

微信支付二维码

微信 赏一包辣条吧~

支付宝支付二维码

支付宝 赏一听可乐吧~

评论

0条评论

发表评论

电子邮件地址不会被公开。 必填项已用*标注