How to check if the table exists in teh database

Hi,
I am using MS Acess and how do i check using the query if the table already exist in the db?
What is the exact query. Can any one help me.
Thanks
Deepti

This will do it for you and print out the results using JDOM. - %
package database;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.output.XMLOutputter;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
public class TableLister
   public static final String DRIVER = "sun.jdbc.odbc.JdbcOdbcDriver";
   public static final String DATABASE = "jdbc:odbc:DRIVER={Microsoft Access Driver (*.mdb)};DBQ=C:\\Documents and Settings\\Michael\\My Documents\\Projects\\Java\\Forum\\data\\DataConnection.mdb";
   public static final String USERNAME = "admin";
   public static final String PASSWORD = "";
   public static void main(String[] args)
      Connection conn = null;
      ResultSet tables = null;
      String driver = "";
      try
         driver = ((args.length > 0) ? args[0] : DRIVER);
         String url = ((args.length > 1) ? args[1] : DATABASE);
         String username = ((args.length > 2) ? args[2] : USERNAME);
         String password = ((args.length > 3) ? args[3] : PASSWORD);
         Class.forName(driver);
         conn = DriverManager.getConnection(url, username, password);
         DatabaseMetaData meta = conn.getMetaData();
         // Bring back ALL tables and views, including SYSTEM tables.
         tables = meta.getTables(null, null, null, null);
         ResultSetMetaData rsmd = tables.getMetaData();
         int numColumns = rsmd.getColumnCount();
         List columnNames = new ArrayList();
         for (int j = 0; j < numColumns; ++j)
            columnNames.add(rsmd.getColumnName(j + 1));
         Element root = new Element("tables");
         int tableCount = 0;
         while (tables.next())
            Element table = new Element("table");
            table.setAttribute("id", Integer.toString(++tableCount));
            for (int j = 0; j < numColumns; ++j)
               Element column = new Element((String) columnNames.get(j));
               column.setText(tables.getString((String) columnNames.get(j)));
               table.addContent(column);
            root.addContent(table);
         conn.close();
         Document doc = new Document(root);
         XMLOutputter outputter = new XMLOutputter("   ", true);
         System.out.println(outputter.outputString(doc));
      catch (ClassNotFoundException e)
         System.err.println("Couldn't load JDBC driver class " + driver);
         e.printStackTrace();
      catch (SQLException e)
         System.err.println("SQL state: " + e.getSQLState());
         System.err.println("SQL error: " + e.getErrorCode());
         e.printStackTrace();
      catch (Exception e)
         e.printStackTrace();
      finally
         close(tables);
         close(conn);
   public static void close(Connection c)
      try
         if (c != null)
            c.close();
      catch (SQLException e)
         e.printStackTrace();
   public static void close(Statement stmt)
      try
         if (stmt != null)
            stmt.close();
      catch (SQLException e)
         e.printStackTrace();
   public static void close(ResultSet result)
      try
         if (result != null)
            result.close();
      catch (SQLException e)
         e.printStackTrace();
}

Similar Messages

  • How to check whether a table exists in database

    test9997 is table already made in database with 3 columns :1st-varchar,2nd-number,3rd-number
    declare
    var1 varchar2(20);
    var2 number(20);
    var3 number(20);
    begin
    plvar1 :='this is again pl/sql';
    plvar2 := 12;
    plvar3 := 13;
    IF (???? condition for existence of table say test1111??????) then
    create table test1111(
    var1 varchar2(20);
    var2 number(20);
    var3 number(20);
    insert into test1111(plvar1,plvar2,plvar3);
    else
    insert into test1111(plvar1,plvar2,plvar3);;
    end if;
    end;
    in the above code i want to check existence of a table and insertion or updation will be based on it after creation if it doesnt exist.
    how to do it
    please help asap

    You're in the wrong forum (this one is for issues with the SQL Developer tool). You'll get more answers in the SQL And PL/SQL forum.
    Have fun,
    K.

  • How to check if internal table exists in dynamical called subroutine ?

    Hi,
    in a dynamically called subroutine i'm using a internal table, but in some calls this table is not exist.
    How can i check in the code whether the internal table exist or not ?
    regards,
    Hans

    In Horst Keller's blog /people/horst.keller/blog/2005/05/27/abap-geek-10--everything-functions-150-but-how my issue is talked about :
    All other parameters are handled in a way as they were declared as global data objects in the top include of the function group, that can be used only during the execution of the function module: They are visible throughout the function group but you can access them only while the function module is active. If you access such a parameter and the respective function module is not executed, you get the runtime error GETWA_NOT_ASSIGNED (Why? Well, technically thos guys are represented via field symbols which are valid only during the runtime of the function module).
    The code is in SD pricing. Sometimes the code is called from function module PRICING_BUILD_XKOMV or PRICING_SUBSCREEN_PBO where TKOMV is defined as globalized parameter.
    And sometimes it is called from function module PRCING_CHECK where TKOMV is NOT defined as parameter.
    In the call of last function the dump occures on the ASSIGN statement :
         data: ls_tkomv like line of tkomv,
                  lv_tablename(30) type c value 'TKOMV[]'.
        field-symbols: <lfs> type any table.
         assign (lv_tablename) to <lfs>.
         if <lfs> is assigned.
    Any suggestions to solve the issue ?
    regards,
    Hans

  • How to check if the path exists and if not, create it

    I'm trying to check if the path given by the user already exists. In case it doesn't, I'd like to create a folder with name given in the same directory.
    Let's say path_1: "C:\folder1" and path_2: "C:\folder2", and suppose that folder1 exists but folder2 doesn't. Then if the path given by the user is the path_1, then ok, nothing happens, but if it is the path_2, then the programm should realize that it doesn't exist in C:\ and should ask you whether you want to create it or not.
    I know how to do that for files, but not for folders!
    Thanks in advance

    hi guys,
    i`m new at this so im gonne prob. ask a noob`s question...
    i have the same issue as in the title.
    but when i run :
                                              int a,b,c,d,folderexist=-1;
                                             switch (event)
                                                       case EVENT_COMMIT:
                                                                                 GetCtrlVal (panelHandle, PANEL_NAME, name);
                                                                                 folderexist = GetFileAttrs (name, &a, &b, &c, &d);
                                                                                 if (folderexist==-1)
                                                                                           MakeDir (name);
                                                                                           sprintf...........
                                                                                 else.......
    if the folder do exists it works perfectly.
    if it doesnt - it breaks the run and gives me the message :
                          NON-FATAL RUN-TIME ERROR: "NewScap.c", line 317, col 27, thread id 0x00001B98: Library function error (return value == -1 [0xffffffff]).
    (and mark the getfileattrs line in blue)
    and when i check the "folderexits" value it shows 2!? not 1 not 0 not even -1, but 2...
    can somone please help ?
    thanks 
    Adi.

  • How to check if the member exists in essbase cube using IF cond.

    Hello,
    I have a requirement to validate certain accounts and if they exist or not and use them in calc. We have certain list of percent accounts which have some driver amounts. If the user selects the parent account, it should automatically calc with percent accounts to generate the values for all its children.
    The issue is we have lots of accounts and lots of percent accounts, its not that all accounts have the percent accounts. thats the problem.
    When I Fix at a high level of accounts, am getting this error which says that member doesnt exists and return empty member set.
    Error executing formula for [Revcnt] (line 49): attempt to cross a null member in function [@X]
    Its the same even if I use Set Emptymembersets ON;
    The script is below,
    FIX(@Relative({SelectAccount},0),
    "Revcnt"(
    IF(@ISMBR(@MEMBER(@CONCATENATE(@NAME(@CURRMBR("Account")),"%"))
    Condition ;
    ENDIF);
    ENDFIX
    Is there a command to validate if the member exists in the cube or not???
    We are using 11.1.2.1 Essbase on Windows 64bit.

    The silly question first:
    Why not user dynamic calc for the members you need? When updating the structure, you create the formula. Your verification if a member exists will be done in, for example, a select statement that create the dimension.
    Now the complex idea:
    Is it possible in your application recreate the script every time you update the dimension?
    My example:
    Here we have a cube that change the account dimension very often. So the cube have an CalcScript that need to be updated every time the dimension changes.
    For that purpose, we have a process that read the database and recreate the calc with the correct members.
    I never tested that solution with calc manager, but i think it's less complex than recognize the member itself during calculation.

  • How to check odi master repository exist in oracle database?

    Is there way to check the ODI master repository is exist in oracle database or any api to test that?
    Your help much appreciated.

    Thanks for you reply,
    That's fine, i think you aware of that, once open the topology manager "topology.bat", you can test the master repository, if you give any existing database user but its not master rep user, that throw exception "Master repository is not installed on this connection".
    I want know what are tables and data's are getting verified during the connection test.
    I think If you know regarding above my question, that will solve my problem.
    Thanks

  • How do I get the table of contents to toggle? I opened it while reading one book I had checked out from my library, but it is still open when I start another book. I am using Adobe 4 and Windows 8.1 on my PC.

    How do I get the table of contents to toggle? It has remained open since I opened it while reading two books ago. Thanks for the help.

    Thank you for your advice. I followed your directions, but came up with the same results. However, I did discover that whenever I open up the iPhoto Library that is already existing on my MacBook a certain set of pictures shows up. But then when I open up the iPhoto Library from the Hard drive another set of pictures shows up. BUT not ALL of my pictures are showing up on the iPhoto Library from the hard drive. At least the last two years of pictures are not showing up?! Actually, it appears that all the pictures are there from when I started using iPhoto about 5 years ago up until around the time that I got my iMac desktop computer and started using that (2 years ago). I have noticed that more recent videos I have made are showing up in a folder on the hard drive, but will not appear when I open up iMovie?! Any ideas on how to access my pictures from the last 2 years off of the hard drive???

  • How to check for the sub folder in the document library Is already Exist using CSOM?

    Hi,
    My requirement is to create the  folder and sub folder in SharePoint document library. If already exist leave it or create the new folder and the subfolder in the Document library using client side object model
    I able to check for the parent folder.
    But cant able to check the subfolder in the document library.
    How to check for  the sub folder in the document library?
    Here is the code for the folder
    IsFolder alredy Exist.
    private
    string IsFolderExist(string InputFolderName)
    string retStatus = false.ToString();
    try
    ClientContext context =
    new ClientContext(Convert.ToString(ConfigurationManager.AppSettings["DocumentLibraryLink"]));
                context.Credentials =
    CredentialCache.DefaultCredentials;
    List list = context.Web.Lists.GetByTitle(Convert.ToString(ConfigurationManager.AppSettings["DocumentLibraryName"]));
    FieldCollection fields = list.Fields;
    CamlQuery camlQueryForItem =
    new CamlQuery();
                camlQueryForItem.ViewXml =
    string.Format(@"<View  Scope='RecursiveAll'>
    <Query>
                                            <Where>
    <Eq>
    <FieldRef Name='FileDirRef'/>
    <Value Type='Text'>{0}</Value>
                                                </Eq>
    </Where>
    </Query>
                                </View>",
    @"/sites/test/hcl/"
    + InputFolderName);
                Microsoft.SharePoint.Client.ListItemCollection listItems = list.GetItems(camlQueryForItem);
                context.Load(listItems);
                context.ExecuteQuery();
    if (listItems.Count > 0)
                    retStatus =
    true.ToString();
    else
                    retStatus =
    false.ToString();
    catch (Exception ex)
                retStatus =
    "X02";
    return retStatus;
    thanks
    Sundhar 

    Hi Sundhar,
    According to your description, you might want to check the existence of sub folder in a folder of a library using Client Object Model.
    Please take the code demo below for a try, it will check whether there is sub folder in a given folder:
    public static void createSubFolder(string siteUrl, string libName, string folderServerRelativeUrl)
    ClientContext clientContext = new ClientContext(siteUrl);
    List list = clientContext.Web.Lists.GetByTitle(libName);
    CamlQuery camlQuery = new CamlQuery();
    camlQuery.ViewXml =
    @"<View Scope='RecursiveAll'>
    <Query>
    <Where>
    <Eq>
    <FieldRef Name='FSObjType' />
    <Value Type='Integer'>1</Value>
    </Eq>
    </Where>
    </Query>
    </View>";
    //camlQuery.FolderServerRelativeUrl = "/Lib1/folder1";
    camlQuery.FolderServerRelativeUrl = folderServerRelativeUrl;
    ListItemCollection items = list.GetItems(camlQuery);
    clientContext.Load(items);
    clientContext.ExecuteQuery();
    Console.WriteLine(items.Count);
    if (0 == items.Count)
    //create sub folder here
    Best regards
    Patrick Liang
    TechNet Community Support

  • How do I check if a table exists

    I have some embedded SQL statements to create tables and indexes
    in a database. These tables may or may not already be there. I
    would like to be able to drop the table(s) first, then create
    them. Unfortunately, an error is generated if I drop a table
    that does not exist.
    Can someone send me the proper SQL command to check if a table
    exists before dropping it in Oracle?
    TIA
    Eric
    null

    I have some embedded SQL statements to create tables and indexes
    in a database. These tables may or may not already be there. I
    would like to be able to drop the table(s) first, then create
    them. Unfortunately, an error is generated if I drop a table
    that does not exist.
    Can someone send me the proper SQL command to check if a table
    exists before dropping it in Oracle?
    TIA
    Eric
    null

  • How do I see the tables in an existing business area and add tables to it

    Hi
    I am having a business area which contains a number of business folders.
    I am creating a new custom folder in it but i dont know if the table exists in the business area or not. How can I see the lisst of tables which are being used by the business area.

    Hi,
    Easiest way is to look at the folder properties using the administrator tool, you can see there the objects the folder is created on.
    Another way is to create a SQL to query your needs.
    You can find here in the forum several SQL regarding the connection between folders and BA.
    In the folders table you will be able to see the source of it.
    Of course that for custom folder you will need to see the SQL to get your requirment.
    Tamir

  • How to check whether a file exist in the program folder or not?

    Hi guys,
    how to check whether a file exist in the program folder or not? Let is say i recieve a file name from user then i want to know if the file is there not and act on that base.
    abdul

    Look at the class java.io.File and the .exists() method:
    http://java.sun.com/j2se/1.4/docs/api/java/io/File.html

  • Please help me how to check a material does existed group code in system (w

    Hi all,
    Please help me...
    I have inputted quantity for  tx MC 94  but when I input them into  tx MC94, I met  a message " Structure  not yet maintained for  this conbination characterstics". Step by step to show a error message as below:
    Step 1: Launch MC 94
    step 2: Enter Planning
    Step 3: Enter  Prod.Code. Material (ex: enter material code :0101010260008, this code is existed  Prod.Code )
    Step 4: Click on "Inactive Version " button
    ==> A error message is showed.
    Please help me how to check a material does existed group code in system (which table to  check  it)?
    How to record the message" Structure  not yet maintained for  this conbination characterstics" to catch up it in my program?
    Thank in advance.

    Karenloria,
    1. Check in MC8C, which Infostructure is used for Planning type "Planning" or the one you are entering in the intial screen of MC94.
    2. Using transaction MC63 for the infostructure identified in step 1, check the planning hierarchy maintained. If this product is not maintined maintain using MC62.
    You can also check using SE16 transction the current infostructe records(Plan) for the table name = infostructure identified in step 1.
    Regards,
    Prasobh

  • How to check whether the Application Server directory exits or not

    Hi,
    I have a selection screen in which I give the Application server file name(UNIX file) as input. Here, I would like to check whether the Server directory exists or not.
    Let us say, the path I gave in the selection screen is /usr/sap/tmp/testfile.txt . Here, the file name is testfile.txt and the server directory is /usr/sap/tmp . I would like to check whether this directory /usr/sap/tmp exists in the server or not. I am not bothered about the file name as I am going to write data into the file. I am mainly concerned about whether the directory exists in the server or not. and one more thing... this is the Application Server path not the Local path.
    Can anyone help me on the same how to check whether the server directory exists or not.
    Thanks in advance.
    Best Regards,
    Pradeep.

    Also you can use the FM EPS_GET_DIRECTORY_LISTING for this purpose.
      Store the directory name
        l_dpath = p_file+0(l_no).
      Validate the directory of the application server
        CALL FUNCTION 'EPS_GET_DIRECTORY_LISTING'
          EXPORTING
            dir_name               = l_dpath
          TABLES
            dir_list               = l_i_dlist
          EXCEPTIONS
            invalid_eps_subdir     = 1
            sapgparam_failed       = 2
            build_directory_failed = 3
            no_authorization       = 4
            read_directory_failed  = 5
            too_many_read_errors   = 6
            empty_directory_list   = 7
            OTHERS                 = 8.
      If any problem occurs with the directory then display proper
      error message
        IF sy-subrc <> 0.
        Display error message
          MESSAGE e018 WITH 'Problem with directory entered'(008).
        ENDIF. " sy-subrc <> 0
    Regards,
    Joy.

  • How to view all the users existing in a Client

    Hi
    Can any one help me, How to view all the users existing in a Client (Other than SM04 and AL08).
    I want to view not only the active users, but all existing users.
    Thanks in Advance
    Chandra

    Hi,
    Check table devaccess. to get all developers list
    Reward points if helpful.
    Regards,
    Mukul
    Edited by: Mukul Sharma on Jun 2, 2008 12:10 PM

  • Example of generating excel dynamically in ssis? geting error [Excel Destination [190]] Error: Opening a rowset for "Excel_Destination$" failed. Check that the object exists in the database.

    example of generating excel dynamically in ssis? geting error [Excel Destination [190]] Error: Opening a rowset for "Excel_Destination$" failed. Check that the object exists in the database.

    Hi Vijay
    Can you be little bit more specific, did you receive this error when you are designing this pacakge using BIDS
    Becuase when you are designing this pacakge in BIDS, you need to manaually create a excel sheet manually for the first time you run,
    are you creating excel sheet using execute sql task and excel connection with input from a variable?
    Did you receive this error in validation phase or execution phase ?
    Can you share your query to create table in excel ?
    http://sqljunkieshare.com/2012/02/28/how-to-create-and-map-excel-destination-dynamically-in-ssis/
    Use the above post

Maybe you are looking for