How to test whether a table exists in database?

How can I test whether a table exists in a database before I execute a query? If the table doesn't exist, I want first create a default table with certain name so that I can always display something in JTable.
Thanks!

Hi,
There are tow ways :
The first one is :
- load the list of tables of the Database in a Vector for exemple by using methode DatabaseMetaData.getTables () and you can test if the table exist or not in the vector by using methode Vector.contains(Object o).
The code seems Like that :
// Loading List Of Tables
// you need to load the list of tables at the begening of
// your class
Vector listOfTables = new Vector();
try
rs = yourConnection.getMetaData().getTables();
while (rs.next())
listOfTables.addElement(rs.getString(3));
catch(SQLException exp)
// When you need to test the existance of table name
// you add this line
if(listOfTables.contains(tableName))
// your code
The second one :
try
//execute your query
catch
//Create your default JTable
I hope that my response can help you!
Ciaou,
Anis

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 test whether XI is sending file or not?

    Hi all!
    My scenario is like this:File(File sender Adapter)->XI->(HTTP receiver adapter)J2EE appl.
    I placed the xml file in D:\somedir on my PC. It is picking up the file, after picking it should post the same xml file to my j2ee appl. My servlet receives the xml file and display it on browser. But nothing is displayed. How to test whether XI is sending XML file to J2EE appl or not? All helpful answers are highly appreciated.
    Thanks!

    Hi
    In the file adapter i set processing mode as delete, it is picking up well from my d:\somedir.
    I got success flag in SXMB_MONI and successful status in RWB->message monitoring?
    Why my servlet is not able to display?
    All helpful answers are rewarded.
    public class DisplayRes extends HttpServlet {
         public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
                        doPost(request,response);
         public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
         BufferedReader brin =new BufferedReader(new InputStreamReader(request.getInputStream()));
         String inputLine;
         StringBuffer sBuf = new StringBuffer();
         while ((inputLine = brin.readLine()) != null)
             sBuf.append(inputLine);
             brin.close();
             PrintWriter out = response.getWriter();
             response.setContentType("text/xml");
             //out.setContentType("text/xml");
             //out.println(sBuf.toString());
             out.write(sBuf.toString());
             out.flush();
    Thanks

  • How to  check whether any table(s) required to shrink on database

    Hi,
    How to check whether any table(s) required to shrink on database
    Regards,
    Venkat

    Venkat wrote:
    Hi,
    Thi is Oracle 10g. How to use this?. I am not using toad etc...
    I am on SQL prompt.
    Regards,
    Venkat.
    for starter
    Generate Script to Shrink Segment Advisor Recommendations [ID 1171054.1]
    Automatic Segment Advisor in Oracle 10g Release 2 (10.2) [ID 314112.1]
    10g and above SEGMENT ADVISOR [ID 242736.1]
    Cheers

  • 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

  • How can i find statistics tables in my database?

    code{
    Upgrade Statistics Tables Created by the DBMS_STATS Package
    If you created statistics tables using the DBMS_STATS.CREATE_STAT_TABLE procedure, then upgrade these tables by executing the following procedure:
    EXECUTE DBMS_STATS.UPGRADE_STAT_TABLE('SYS','dictstattab');
    In the example, 'SYS' is the owner of the statistics table and 'dictstattab' is the name of the statistics table. Execute this procedure for each statistics table.
    the above is one of the post upgrade step for 11gR2. How can i find statistics tables in my database?

    You need to read the complete context of this manual upgrade step:
    Step 33
    Upgrade Statistics Tables Created by the DBMS_STATS Package
    If you created statistics tables using the DBMS_STATS.CREATE_STAT_TABLE procedure, then upgrade these tables by executing the following procedure:
    EXECUTE DBMS_STATS.UPGRADE_STAT_TABLE('SYS','dictstattab');
    In the example, 'SYS' is the owner of the statistics table and 'dictstattab' is the name of the statistics table. Execute this procedure for each statistics table.You need to do this step for any statistics table that you created manually with DBMS_STATS.CREATE_STAT_TABLE.
    Marcus

  • How to test if a column exists in a table

    Hello,
    Using SQL or PL/SQL how do I test if a column exists in a table. For example,
    if column_aa exists in table_1
    then do this....
    else do that....
    Thank you.

    Set ServerOutput On;
    CREATE Table a_Test (
    Col1 NUMBER
    , Col2 NUMBER )
    DECLARE
    lnCol1 NUMBER ;
    lnCol7 NUMBER ;
    PROCEDURE TestColumn( acColName IN VARCHAR2 )
    IS
    lnColX NUMBER ;
    NoColumnExists EXCEPTION;
    PRAGMA EXCEPTION_INIT(NoColumnExists, -904);
    BEGIN
    EXECUTE IMMEDIATE
    'SELECT Max('|| acColName||') FROM a_Test WHERE RowNum = 0'
    INTO lnColX ;
    DBMS_OUTPUT.Put_Line('Column: '||acColName||' exists.');
    EXCEPTION
    WHEN NoColumnExists THEN
    DBMS_OUTPUT.Put_Line('Column: '||acColName||' NOT exists.');
    WHEN Others THEN
    DBMS_OUTPUT.Put_Line( SqlCode ||' '||SqlErrM );
    END
    BEGIN
    DBMS_OUTPUT.Enable ;
    TestColumn( 'Col1') ;
    TestColumn( 'Col2') ;
    TestColumn( 'Col7') ;
    END
    DROP Table a_Test;

  • How to check whether portal user exists or not using UM API.

    Hi Experts,
    Let us say i need to create an user account "PortalUser",i know how to create an user,setting first name,lastname,password for that.
    but here before creating the portal user, i need to check whether that user exists or not.If user already exists ,then i  need to skip the below for creating the user.
    IUserFactory userFact = UMFactory.getUserFactory();
    IGroupFactory groupFact = UMFactory.getGroupFactory();
    IRoleFactory roleFact = UMFactory.getRoleFactory();
    IUser tuser = userFact.getUserByLogonID("PortalUser");
    IUserMaint newUser = userFact.newUser("PortalUser");
    newUser.setFirstName("PortalUser");
    newUser.setLastName("Test");
    newUser.setEmail("PortalUser.Testatgmaildotcom");
    //Locale PortalLanguage = new Locale(Lang.toLowerCase(), "");
    Locale PortalLang=new Locale("en");
    newUser.setLocale(PortalLang);
    newUser.save();
    newUser.commit();
    IUserAccount userAcc = UMFactory.getUserAccountFactory().newUserAccount("PortalUser", newUser.getUniqueID());
    userAcc.setPassword("test1test$");
    userAcc.save();
    userAcc.commit();     
    Thanks in advance.
    Thanks
    Sony.

    Hi,
    Try this code,
    IUserFactory factory = UMFactory.getUserFactory();
    IUser user = factory.getUserByLogonID(userId);
    lastName = user.getLastName();
    firstName = user.getFirstName();
    refer this pdf,its very helpful
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/events/webinars-nw-rig/using%20the%20user%20management%20api%20with%20ep%20applications%20-%20webinar%20powerpoint.pdf
    Regards,
    Sunaina Reddy T

  • 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 find whether the tables are needed or not?

    Friends,
    Difficult situation for me......
    OS: RHEL AS 3.0
    DB: Oracle 9i R2
    I was taking table inventory.....
    i saw many tables starting with SMP..... and EVT.....Nearly 50 tables.
    some are...
    EVT_HISTORY
    EVT_DEST_PROFILE
    EVT_CARRIER_CONFIGURATION
    SMP_USER_DETAILS
    SMP_UPDATESERVICES_CALLED_
    SMP_SERVICE_ITEM_
    SMP_SERVICE_GROUP_ITEM_
    SMP_SERVICE_GROUP_DEFN_
    SMP_SERVICE_DATA_
    SMP_LONG_TEXT_
    SMP_JOB_TASK_INSTANCE_
    SMP_JOB_LIBRARY_
    SMP_JOB_INSTANCE_
    SMP_JOB_HISTORY_
    SMP_JOB_EVENTLIST_
    SMP_JOB_
    SMP_EBU_SAVED_JOB_
    SMP_EBU_ACTIVE_JOB_
    SMP_CREDENTIALS$
    SMP_BRM_TEMP_SCRIPTS_
    SMP_BRM_SAVED_JOB_
    SMP_BRM_RC_CONNECT_STRING_
    SMP_BRM_DEFAULT_CHANNEL_
    SMP_BRM_CHANNEL_DEVICE_
    SMP_BRM_ACTIVE_JOB_
    SMP_AUTO_DISCOVERY_PARMS_
    SMP_AUTO_DISCOVERY_ITEM_
    SMP_AD_PARMS_
    SMP_AD_NODES_
    SMP_AD_DISCOVERED_NODES_
    SMP_AD_ADDRESSES_
    more.........
    Nobody knows whats the table is for....
    Actually we were working with oracle 7.3 upto 2004. On 2004 we upgraded to 9iR2. May be the DBA in that time made some mistake.... i think so....thats why all these tables are still here....
    I was not in the picture during that time.
    Now my question is how can i know whether this table is necessary or not. I asked the developers here they said they are not using these tables. But my manager is afraid to delete these tables.
    now what should i do?

    Hi,
    Yet another request to use my crystal ball.
    We had one pc which is having oracle 9i enterprise manager configured(windows 2000) only to connect the db.
    This remembers me of the Gospel of St. Luke, chapter 2, where it is stated,
    'and they found the child in the manger'.
    This resulted a Jewish theologian to remark: 'The manger? Well, so that must have been their own manger'
    So what does 'the' db mean? The Linux one? Or a separate on Win2000?
    It is quite possible to manage a Linux database using OEM on Win2000, with OMS on Win2000.
    'But our server is not having enterprise manager'. Yet another riddle. Which server? There seem to be at least two.
    1 Now if I drop these tables, will I be able to connect to our database using the windows2k pc through Enterprise Manager?
    Yes, but only in standalone mode, and you can't use OEM alerts, and jobs anymore. You would be better off using Sqldeveloper, as OEM Sql worksheet is a nightmare.
    2 That is your decision.
    3
    oemctl ping oms
    will check whether you have an Oracle Management Server running.
    You already seem to have the Enterprise Manager Repository, so you must have OMS running somewhere. (Why install the repository, if you don't use it)
    Sybrand Bakker
    Senior Oracle DBA

  • How to test whether AIA got integrated with BRM system successfully

    Is there a procedure to test whether AIA got integrated with BRM system successfully.How can i test whether BRM Adapter is able to connect to BRM system.
    Thanks well in advance
    Santosh

    Hi Santhosh,
    I hope you are using AIA 2.0/2.0.1 for Comms and trying to integrate BRM with Siebel.
    1. To check BRM & Siebel integration using AIA. (BRM is the Product master gets synched with Siebel.)
    a) Create a new Product in BRM pricing center(Provide product name, Service type)
    b) Select Event(Single time purchase event)
    c) Provide rating for the product
    d) Commit after product creation(Check in BPEL process, whether all the instances are went through successfully)
    e) Check Siebel Catalog, whether product got synched from BRM
    2. To check whether BRM Adapter connected to BRM,
    a) Login into Oracle Application server
    b) Select OC4J instance, where your AIA is running
    c) Select Applications
    d) In view drop down select "StandAlone Resource Adapters"
    e) Check the status (green or red) in the installed BRM adapter
    If you haven't deployed BRM Adapter read the installation guide to deploy it.
    Regards,
    Ziaur Rahuman

  • How to test an image file existing or not

    Hi Everyone,
    I want to test whether an image file exists or not before setting the url of an image component in JSF to it. Following is my code:
    File testFile = new File(image_path + "/p1.jpg");
    if(testFile.exists()){
    info("file exists");
    }else{
    info("file not exists");
    this.myImage.setUrl(image_path+"/p1.jpg");
    Althoug the p1.jpg can be linked to myImage, the existence test always fails. That is, I got the message "file not exists" even though it is already displayed.
    What did I do wrong?
    Thanks in advance,
    Message was edited by:
    field

    File testFile = new File(image_path + "/p1.jpg");Is image_path an absolute path or relative path?

  • How to check whether transport path exist between two systems in sld??

    Hi,
         I have two systems namely 'A' and 'B' and created business systems for both of them.Then i created transport path between the two systems.How i check whether what i have done is right in SLD.

    <b>WRT to CMS</b>
    am not sure with this but u can try:
    1. Start CMS: http://<host>:<J2EE Engine http port>/webdynpro/dispatcher/sap.com/tcSLCMS~WebUI/Cms.
    2. Goto lansdscape configurator and check there
    Message was edited by:
            Prabhu  S

  • How to mirroring/replicating a table from one database to another database?

    I am having a table in 10g Database.
    I want to mirror this table in 9i Database.
    How to do this?

    1) Just to clarify, it is quite possible to use Streams between a 9i and 10g database (note for future reference that specifying actual database versions, i.e. 9.2.0.4 or 10.2.0.4 rather than marketing labels is generally helpful because there may be differences between different 9i and 10g releases)
    2) Are you setting up one-way replication? Or will changes be made on both databases, implying the need for multi-master replication?
    3) Why doesn't the table have a primary key? Could you declare a primary key? If not, you'd have to use the ROWID (i.e. specify WITH ROWID when creating the materialized view log and the materialized view) which tends to cause maintenance issues down the line. It really doesn't make sense to replicate a table without a primary key-- it really doesn't make sense to design a table without a primary key the vast majority of the time.
    Justin

  • How to select a new table in logical database after creating the Infoset

    I have created a abap query report ,i have used logical data base ADA in the infoset in SQ02.In the logical database i had selected only two tables then ANALV and ANLB.Now my client wants one more field to be added and thats is from table ANEK.Now i need to select this table in logical database ADA.
    Please assist on how to select another table available in the Logicaldata base now which i didnt select when i created the query

    Markus,
    I have now selected the additional field Posting date in Document ANEK -BUDAT .Earlier the report had the fields from ANLCV - Current acquisition value ,ordinary dep posted selected for  the output.
    When i run the query after adding this new field ANEK-BUDAT the below warning  is generated  by system :
    The query specifications cannot be used to generate a list,
    i.e. the query will probably not return the list you desire.
    If you still want to execute the query, please use the
    "Generate" function
    -> 'Generate'
    Fields from parallel tables within a line*
    Line: 01
    Field: Posting Date in the Document
    (ANEK-BUDAT, table ANEK)
    Field: Ordinary depreciation posted
    (ANLCV-NAFA GEB, table ANLCV)
    Fields from parallel tables within a line*
    Line: 01
    Field: Posting Date in the Document
    (ANEK-BUDAT, table ANEK)
    Field: Current asset acquisition value
    (ANLCV-LFD KANSW, table ANLCV)
    2 warnings for query QUERY ***
    Please advice .How get this new field added.

Maybe you are looking for