Hi,
i had made a program where I would read data from excel files and store them in tables in mysql. But my program at the beginning would like to give the directory of where the excel files are. For each one excel file I would like to have on table. When the user would give the path, the programwould catch all the .xls files and would continue in the rest program. Each table would have the name of the excel file without the last .xls.
How can I make the program to check whether a table already exists and if so to continue in the next excel file? To be more specific I would like to check first if a table already exist for the excel file and if does to continue in the next excel file in the directory.
The code that I have written is the below but I doesn't work the way I would like.
for (int i = 0; i < listOfFiles.length; i++) { if (listOfFiles[i].isFile()) { files = listOfFiles[i].getName(); if (files.endsWith(".xls") || files.endsWith(".XLS")) { List<File> xlsFiles = new ArrayList<File>(); xlsFiles.add(listOfFiles[i]); String[] parts = files.split("\\."); String tablename = parts[0]; { DatabaseMetaData dm = (DatabaseMetaData) con .getMetaData(); // check if table exist ResultSet rs = dm.getTables(null, null, tablename, null); if (!rs.next()) { System.out .println("The table just created. The data are"); } else { System.out .println("The tables already exists.Please try again"); return; } }