我想创建一个临时表,其列数等于数组中的列数。 我该如何实现这一目标?
提前致谢。
Java类方法:
public String insertExcelDataInTable(String userName, int srNum,String fileName, int fileNum, String[][] data) {
int numOfColumns=data[0].length;
for(int i=1;i<numOfColumns;i++){
String col="col"+i;
System.out.println(col);
String creatQuery="CREATE TABLE upload_temp (ExcelNumber INT NOT NULL,ExcelName VARCHAR(60) NOT NULL,..** Number of Columns From an array** ...);";
}
}
答案 0 :(得分:1)
public String insertExcelDataInTable(String userName, int srNum,String
fileName, int fileNum, String[][] data) {
int numOfColumns=data[0].length;
String creatQuery = "CREATE TABLE upload_temp (ExcelNumber INT NOT NULL,ExcelName VARCHAR(60) NOT NULL, __COLUMNS_TO_BE_REPLACED__ );";
String columnsDeclaration = "";
for(int i=1;i<numOfColumns;i++) {
String col="col"+i;
System.out.println(col);
columnsDeclaration += col + " VARCHAR(100) NULL ";
if(i < numOfColumns - 1){
columnsDeclaration += ",";
}
}
creatQuery = creatQuery.replace(__COLUMNS_TO_BE_REPLACED__, columnsDeclaration);
return creatQuery;
}