Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: check if table exists from a list of files in a directory

  1. #1
    Junior Member
    Join Date
    Apr 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default check if table exists from a list of files in a directory

    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;
    							}
    						}


  2. #2
    Senior Member PhHein's Avatar
    Join Date
    Mar 2013
    Location
    Germany
    Posts
    609
    My Mood
    Sleepy
    Thanks
    10
    Thanked 93 Times in 86 Posts

    Default Re: check if table exists from a list of files in a directory

    The code that I have written is the below but I doesn't work the way I would like.
    What does it do? What do you expect?

Similar Threads

  1. Java program which can list all files in a given directory
    By JavaPF in forum Java Programming Tutorials
    Replies: 8
    Last Post: July 9th, 2013, 03:38 AM
  2. Replies: 1
    Last Post: May 25th, 2013, 05:13 AM
  3. to get name of all files from a particular directory to a list..
    By Himali in forum File I/O & Other I/O Streams
    Replies: 5
    Last Post: April 7th, 2012, 06:08 AM
  4. How to copy files from one directory to another directory
    By kewlkeny in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: January 25th, 2012, 07:36 AM
  5. Java program which can list all files in a given directory
    By JavaPF in forum Java Code Snippets and Tutorials
    Replies: 5
    Last Post: November 3rd, 2009, 09:42 AM

Tags for this Thread