Check table existence method

I have the following Java method that is suppose to determine whether a given table exists or not:
public boolean tableExists(String table) {
String defstmt = "select TABLE_NAME from ALL_TABLES where (TABLE_NAME = '" + table + "')";
System.err.println("tableExists: stmt = " + defstmt);
tc.executeSEL(defstmt);
ResultSet rs = tc.getRS();
String tname = new String();
try {
while (rs.next()) {
rs.getString(tname);
System.err.println("tableExists.try: tname = " + tname);
rs.close();
return true;
catch (SQLException ex) {
System.err.println("tableExists.catch: tname not found");
try {
rs.close();
catch (SQLException ex1) {
return false;
Since this one didn't appear to work reliabily a friend suggested the following:
public boolean tableExists(String table) {
boolean exists = false;
String defstmt = "select TABLE_NAME from ALL_TABLES where (TABLE_NAME = '" + table + "')";
System.err.println("tableExists: stmt = " + defstmt);
if (tc.executeSEL(defstmt)) {
ResultSet rs = tc.getRS();
try {
exists = rs.first();
// This returns false if the rs is empty
// This should be sufficient if the query will return zero rows or one row.
// If there's a possibility that the query could return more than one row
// (for example if multiple schema data is in there and a table name
// might be duplicated), then this section will need to be more picky.
System.err.println("tableExists.try: tname found");
catch (SQLException ex) {
System.err.println("tableExists.catch: tname not found");
try {
rs.close();
catch (SQLException ex1) {
return exists;
Bottom line; neither method seems to be able to determine whether the table exists. Someone out there got any suggestions?
Thanks in advance
RCulp

The method "tc.executeSEL" is in a class "TableConnector" which I use to hold connection data and execute SQL statements. A new instance of the "TableConnector" class is created for each table prior to the check for existence. The method itself is boolean, returning true or false if the SQL runs successfully:
public boolean executeSEL(String inpstmt) {
rs = null;
try {
Connection conn = ConnectionData.getConnectionData().openConnection();
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
rs = stmt.executeQuery(inpstmt);
return true;
//debugdumpRS(rs);
catch (SQLException ex) {
System.err.println("SEL Statement = " + inpstmt);
System.err.println("Error code = " + ex.getErrorCode());
System.err.println("Error message = " + ex.getMessage());
System.err.println("SQL state = " + ex.getSQLState());
return false;
/*FINALLY CAN NOT BE USED HERE; ERASES THE RESULT SET
finally {
if (stmt != null) {
try {
stmt.close();
catch (SQLException ex) {
System.err.println("Error code = " + ex.getErrorCode());
System.err.println("Error message = " + ex.getMessage());
The TableConnector class also has a get method for the ResultSet:
public ResultSet getRS() {
return rs;
I'll try your suggestion and post the result.
Thanks
RCulp

Similar Messages

  • Check table existence and delete entire records using Server 2005

    I am trying to delete the entire record of table after confirmation of Table existence using SQL Server 2005 SP3,
    query is as follows - 
    USE smsDB;
    GO
    IF (OBJECT_ID('organTable', 'U') IS NOT NULL)
    BEGIN
    PRINT 'Table Exists'
    DELETE FROM organTable;
    END
    ELSE
    BEGIN
    PRINT 'Table not Exists'
    END
    GO
    please help to delete the entire table records...
    Pl. Mark/Proposed as Answer if found your solution Vote as Helpful if related to your topic. Always Motivate others by performing this Action.

    You code looks good.
    Are you facing any issues? Please explain.
    You can even try with truncate table...
    IF (OBJECT_ID('organTable', 'U') IS NOT NULL)
    BEGIN
    PRINT 'Table Exists'
    --DELETE FROM organTable;
    Truncate Table OrganTable
    END
    Sir, first of all thanks for reply & giving me your valuable time,
    i have learned some of the issues or dependencies with Truncate query, which are as follows -
    - Are referenced by a FOREIGN KEY constraint. (You can truncate a table that has a foreign key that references itself.)
    - Participate in an indexed view.
    - Are published by using transactional replication or merge replication
    because my tables exist some of above restrictions, please guide, is it right to use the truncate?
    Pl. Mark/Proposed as Answer if found your solution Vote as Helpful if related to your topic. Always Motivate others by performing this Action.

  • How to check the table existence in JPA

    1) is there a way I can check for existence of the table using JPA, before I read the rows.
    2) If I want to create two tables with same columns (name, time), Should I create two entity objects to insert? is there a way to use one enity class and specify a table to insert ?
    thanks
    Vamshi

    Try this:
    function findNodes(vNode){
         if (vNode.className === "field"){
              if (vNode.isPropertySpecified("name")===true){
                   var myStateName=new RegExp(vNode.name);
                   var returnValue = GFL.search(myStateName);
                   if (returnValue!=-1){
                        this.ui.oneOfChild.border.fill.color.value="192,192,192";
                        this.access="readOnly";
                   else{  
                        this.ui.oneOfChild.border.fill.color.value="255,255,255";//whatever colour is open access
                        this.access="open";
         for (var a=0;a<vNode.nodes.length;a++){
              findNodes(vNode.nodes.item(a));
    findNodes(xfa.form);
    Kyle

  • How to check (programmatic) existence of a method in a class implementation

    Hi
    I need to check the existence of method in a class in a programmatic way and call it only when it is available otherwise proceed with subsequent steps in my ABAP OO Program. Is there way to do it? This is needed in a customer exit situation and each task is implemented with method and not all tasks would have methods implemented.
    Any feedback is greatly appreciated.
    Thanks

    When you try to call the method dynamically and ifthe method doesn't exist, system would complain by raising the exception cx_sy_dyn_call_illegal_method. You can Catch this exception when you call the method.
    CLASS lcl_test DEFINITION.
      PUBLIC SECTION.
        METHODS:
          check_exist.
    ENDCLASS.                    "lcl_test DEFINITION
    DATA: lo_test TYPE REF TO lcl_test.
    DATA: lv_method TYPE char30.
    lv_method = 'GET_DATA'.
    CREATE OBJECT lo_test.
    TRY.
        CALL METHOD lo_test->(lv_method).
      CATCH cx_sy_dyn_call_illegal_method.
    ENDTRY.
    CLASS lcl_test IMPLEMENTATION.
      METHOD check_exist.
      ENDMETHOD.                    "check_exist
    ENDCLASS.
    Regards,
    Naimesh Patel

  • [svn:bz-trunk] 23143: Certain code needs to check the existence of the class validation validator  (some brokers and other listeners) during message broker init, however the validator was not being created till the very end of the method .

    Revision: 23143
    Revision: 23143
    Author:   [email protected]
    Date:     2011-10-27 06:31:02 -0700 (Thu, 27 Oct 2011)
    Log Message:
    Certain code needs to check the existence of the class validation validator (some brokers and other listeners) during message broker init, however the validator was not being created till the very end of the method.  Promote it to be at the top instead of at the bottom.
    Modified Paths:
        blazeds/trunk/modules/core/src/flex/messaging/config/MessagingConfiguration.java

    Revision: 23143
    Revision: 23143
    Author:   [email protected]
    Date:     2011-10-27 06:31:02 -0700 (Thu, 27 Oct 2011)
    Log Message:
    Certain code needs to check the existence of the class validation validator (some brokers and other listeners) during message broker init, however the validator was not being created till the very end of the method.  Promote it to be at the top instead of at the bottom.
    Modified Paths:
        blazeds/trunk/modules/core/src/flex/messaging/config/MessagingConfiguration.java

  • How to check table difference QUICKLY?( symetic check, hash check, or ...)

    Hi. Everyone.
    I would like to know whether or not there is a difference
    between tables. The two tables are located
    at the differerent location, and network speed is very bad.
    I am considering this two ways as belows.
    1. symeteric check
    (select * from table_A@location1
    minus
    select * from table_A@location2)
    union all
    (select * from table_A@location2
    minus
    select * from table_A@location1)
    2. hash value check using dbms_utility.get_hash_value
    select sum(dbms_utility.get_hash_value(
    "column lists",1,power(2,16)-1)) xx
    from table_A@location1
    select sum(dbms_utility.get_hash_value(
    "column lists",1,power(2,16)-1)) xx
    from table_A@location2
    Which one do you think is faster?
    Additionally, is there better way to check table difference
    as quickly as possible.
    Thanks in advance.
    Have a nice day.
    Ho.
    Message was edited by:
    user507290
    Message was edited by:
    user507290

    Hello
    Another alternative may be to materialise the two remote tables localy and then do the comparison - perhaps using materialised views. If you can get the data locally, you can reliably try a few different methods and figure out which works best.
    I know MINUS can be exceptionaly quick for comparing whole result sets, but it's not suited to all cases...in the same way that using sub queries/not exists is better in some cases than others.
    HTH
    David

  • BPM Scenario :  " Error accessing table SXMS_AS_STATUS method: INSERT"

    Hi all,
    Webservice --> XI -->BW .
    BPM has been used to send to send the response back.
    BPM :
    start ->Receive(Request)> Transformation(Responsemap)>Send(SendtoR/3)->Send(Send Response) ---> stop.
    We are getting the error as " The error is <SAP:Stack>Error accessing table SXMS_AS_STATUS method: INSERT</SAP:Stack>
    There are some messages that Webservice sent and XI received them but this error occured during some process in XI. and this is causing some discrepancy in the data sent and received.
    Any idea what might be the problem ? Is there anything which I need to change in the parameters to rectify this error?
    -Deepthi.

    Hi
    Just check this note , can get some clue
    SAP-Note 1124049
    Regards
    Abhishek

  • Error in lsmw: "Invalid Text ID (Check Table TTXID )

    DEAR ALL,
    I am uploading purchasing order text in material master by Standard Batch/Direct input method.
    In last step Start Direct Input Program it gives error as below.
    "Invalid Text ID (Check Table TTXID )"
    Please give solution
    Regarts
    Atul

    Hi,
    probably you use invalid object ID. All valid object IDs are defined in the table TTXID. For purchase document header it is EKKO and EKPO is for item level.
    Cheers

  • Drop down  ! check table validating ?

    Hi,
    For ALV edit mode i am creating a fieldcatalog-checktable field fill with value ! , then also while in the drop values are get validated with check table?
    It is validating the entry with checktable? why ? after giving  ls_fcat-checktable = '!'.
    * Here YDROP_DOWN field have check tabke values " ", 1, 2
      ls_fcat-fieldname = 'YDROP_DOWN'.    
      ls_fcat-datatype  = 'INT4'.
      ls_fcat-checktable = '!'.
      ls_fcat-no_out    = c_x.
      append ls_fcat to pt_fieldcat.
      describe table pt_fieldcat lines v_rows.
      call method cl_alv_table_create=>create_dynamic_table
        exporting
          it_fieldcatalog = pt_fieldcat
        importing
          ep_table        = g_hts.
      assign g_hts->* to <i_status>.
    Then during the first display
      call method g_grid->set_table_for_first_display
        exporting
          is_layout            = gs_layout
          i_save               = 'A'
          it_toolbar_excluding = i_exclude[]
        changing
          it_fieldcatalog      = gt_fieldcat[]
          it_outtab            = <i_status>[].
      call method g_grid->set_ready_for_input
        exporting
          i_ready_for_input = v_input.  " it will be 1 or 0

    Hi ARS,
    See the below link and i am sure it will help you lot
    /people/srilatha.t/blog/2007/04/16/alv-grid-150-insert-row-function
    /people/david.halitsky/blog/2007/04/24/so-youve-got-to-code-an-editable-alv-inside-an-sap-provided-exit-and-x-function-group
    Problem in ALV
    Thanks
    Seshu
    Message was edited by:
            Seshu Maramreddy

  • Error: Table /1FB/MD___M8006P error in DDIC - Check table with SE14

    Hi Friends,
    I've a problem related to the activation table, if I want to activated always problematic because there are fields POSITION, there are errors like this view :
    Activation of worklist (MST.EKA / 15.04.2011 / 11:20:59 /)
    =========================================================================
    Technical log for mass activation
       See log XXX 20110415112056:ACT
    TABL /1FB/MD___M8006P was not activated
    Check table /1FB/MD___M8006P (XXX/15.04.11/11:20)
    POSITION is a reserved word (Select another field name)
    Field name MANDT can be provided in this system. Please do not use.
    Field name SID can be provided in this system. Please do not use.
    Field name TABNAME can be provided in this system. Please do not use.
    Field name FIELDNAME can be provided in this system. Please do not use.
    Field name AS4LOCAL can be provided in this system. Please do not use.
    Field name AS4VERS can be provided in this system. Please do not use.
    Field name POSITION can be provided in this system. Please do not use.
    Index /1FB/MD___M8006P-01 is not in the customer namespace
    Table /1FB/MD___M8006P must be created in the database
    Check on table /1FB/MD___M8006P resulted in errors
    =========================================================================
    End of activation of worklist
    please guide what must I do ... ??
    Thanks
    Eka Sumargo

    Hi Eka,
    the acticvation will not work because of the existence of the field POSITION
    "POSITION is a reserved word"
    POSITION is a reserved word; these reserved words are stored in table
    TRESE, and the reason should be there also.
    You will have to change the field name for the activation to complete.
    Kind regards,
    Paul

  • How to check the existence of DB400 library from java

    Hi all,
    I actunally need to validate a DB400 library via java. so is there any way to check the existence of DB400 library from java side.
    Thanks in advance.

    Hi Sarvan,
    You might not even need a function to tell you if a record exists or not.
    Here in below example i do a check with exists .you will find couple of other ways too..
    create table t as select * from emp where deptno=10now i set salary of every person present in table 'T' to 1111 in emp table.
    update emp e
    set sal=1111
    where exists
            (select 1
              from t
              where t.empno=e.empno) Remember that plain SQL will always outperform PLSQL.
    Hope it helps
    CKLP
    Edited by: CKLP on Sep 26, 2011 3:41 AM

  • Programmatically check the existence of objects in the system

    Hi,
    Is there a way to programmatically check the existence of objects? The idea is I'll accept a list of names of objects and their object types and then programmatically check their existence in the system?
    Can you point me to a resource on how to do it?
    Thanks in advance.
    --Carl

    Hi.
    All custom objects (z, y) being referred to a program. May it be z or y table, data element, domain, sapscript form, function module/group.
    The goal is actually to be able to transport a program from a source machine to a target machine. The objects being referred to from the program must also be transported, of course, for it to run properly. Thus, the need to check the objects' existence.
    Thanks.
    --Carl

  • Check for existence of a record

    I have a table XX_TEMP. Let us say the columns are inventory_item, organization_id and description
    The values are:
    Inventory_item
    Organization
    Description
    200
    m1
    Sample
    200
    m2
    Not Sample
    400
    m4
    check
    700
    m5
    Test
    I just want to check the existence of an item in the table, I have written two queries and would like to know which one is better in terms of performance:
    Q1:
    select count(1) from xx_temp where inventory_item=200 and rownum=1;
    Q2:
    select count(1) from dual where exists (select 1 from xx_temp where inventory_item=200);
    Both Q1 and Q2 return the same result. In fact, I was surprised with the result from Q1 as I expected that the rownum would be evaluated after the where condition. I expected Q1 to return 2
    I thought that the below query:
    select count(1) from xx_temp where inventory_item=200;
    and Q1 would return the same result as rownum would be evaluated at end. In effect, I've 2 questions:
    1. Isn't rownum calculated at the end?
    2. What is the best way in terms of performance to check for an existence of record?

    Internally this is how it works:
    select count(*) from xx_temp where inventory_item=200 and rownum=1;
      COUNT(*)
             1
    1 row selected.
    Execution Plan
       0       SELECT STATEMENT Optimizer Mode=ALL_ROWS (Cost=4 Card=1 Bytes=13)
       1    0    SORT AGGREGATE (Card=1 Bytes=13)
       2    1      COUNT STOPKEY
       3    2        TABLE ACCESS FULL XX_TEMP (Cost=4 Card=2 Bytes=26)
    Statistics
              5  user calls
              0  physical read total multi block requests
              0  physical read total bytes
              0  cell physical IO interconnect bytes
              0  commit cleanout failures: block lost
              0  IMU commits
              0  IMU Flushes
              0  IMU contention
              0  IMU bind flushes
              0  IMU mbu flush
              1  rows processed
    Plan
    1 Every row in the table XX_TEMP  is read.
    2 Processing was stopped when the specified number of rows from step 1 were processed.
    3 The rows were sorted to support a group operation (MAX,MIN,AVERAGE, SUM, etc).
    4 Rows were returned by the SELECT statement.
    COUNT STOPKEY knows how many rows you want and will just keep calling its child function under it in the execution plan tree to get more and more rows, until the required amount of rows have been returned. Here it stopped at 1 iteration.
    And to answer your second question : as to which is the fastest way to to check  for an existence of record :
    Answer would be it depends on your requirement.  possible answers are :  Rowid --  fastest way to check for a row.   similar answers can be Index etc.. but all this is relative to what you work with.
    Cheers,
    Manik.

  • Input Data Validation Of A Field Associated To A Check Table

    Hello,
    Does Web Dynpro have an inherent functionality to validate input fields associated to a check table?
    For example I created a structure with the field UNAME and defined USR02 as the check table for it.  And then I defined a UI InputField in my View and bind it to UNAME.  Web Dynpro does NOT seem to do an automatic validation to check if the value entered by the user exists in USR02. 
    Is there an interface or class that can be called in method WDDOBEFOREACTION to do the validation.  Or do we just have to do some manual validation using SELECT statements?
    Thanks.
    Giscard

    Hi Giscard,
    Web Dynpro does automatic validation when  you assign the check table  .
    You need not write any code as such.
    If the data which you entered is incorrect ,when you are trying to perform any action(like saving the data in data base or performing any further action with the wrong data that ia entered )
       the system throws an error message as"USERNAME -
    NOT IN THE SYSTEM'.
    Regards,
    Priya

  • Showing description and not key when using check tables in Web UI

    Hi,
    I have added an field using EEWB to Opportunity Item, and connected it to check table CRMC_CUSTGRP1. It shows fine, and we can select from the check table using the web ui.
    However it shows the key column and not description column from the table. Is there a way to make the web ui show description instead of the key?
    Regards
    Mattias

    Hi,
    I debugged GET_V_S_STRUCT, and it tries calling 
    ME->VIEW_DESCRIPTOR->GET_FIELD_GEN_VALUEHELP_DL
    ME-VIEW_DESCRIPTOR is an instance of class CL_BSP_DLC_VIEW_DESCRIPTION, which does not contain the method GET_FIELD_GEN_VALUEHELP_DL, and obviously it throws an CX_SY_DYN_CALL_ILLEGAL_METHOD exception, which leaves the value table empty.
    Do you have any idea why, or have I missed something fundamental?
    Regards
    Mattias
    Edited by: Mattias Johansson on Nov 14, 2008 11:05 AM

Maybe you are looking for

  • Please help, I am having a nightmare with upgrading iphone 4

    Hello everyone, My dad asked me to upadte his iphone for him and I just can't get it to work now. I backed the iphone 4 up on itunes and then ran the update, initially when it had finished it wouldn't allow me to access my wifi so I looked that up an

  • Running CMP EJB in remote OC4J fails, works in embedded. Oracle 9i

    I more or less followed the EJB Tutorial (in the help) for creating a session-entity bean facade from Oracle 9i tables. Everything executes correctly in the embedded oc4j but it fails on the remote oc4j with java.sql.SQLException: Invalid column name

  • Can't find class org/apache/jk/apr/AprImpl

    Hi I have Tomcat 4.1.29 and Apache Web Server 2.0.48 installed. I have used this tutorial since I'm a newbie :( http://www.gregoire.org/howto/Apache2_Jk2_TC4.1.x_JSDK1.4.x.html My problem is when I try to regroup them, I obtained this error error.log

  • Table breaking - More Newbie Q's

    http://www.oerica.com/test.htm The text in table cell breaks when it extends past the width of cell. I've tried tabe-layout__fixed, min/max widths, div tag within the table cell. Not sure what I am missing.

  • Windows not genuine error (0x8007000D)

    I keep getting a message telling me that windows is not genuine and my background has disappeared. I tried doing a system restore and this worked but the next time I turned on my laptop it was again saying that my copy of windows is not genuine. I am