Deleting records from a Database using JTable

Hello!
I have a JTable that displays records from a database and a Jbutton .
If i press the button i want that the record coresponding to selectedRow(from the JTable) to be erased from the database.How can i manipulate selectedRow from JTable to do that?
Pls any suggestions (and if it's possible +code)?
Thanks!

Hi Margot,
Let's assume that you have created a table using vectors. Simply remove the element from the vector at row selected and redraw. Maybe not the greatest solution but should work.
Vector rowData = new Vector();
//read in values for each row
Vector headers = new Vector();
//add your headers
JTable table = new JTable(rowData, headers);
int row = table.getSelectedRow();
rowData.removeElementAt(row);
table = new JTable(rowData, headers);HTH,
Chris

Similar Messages

  • Getting error while deleting rows from the database using the View Object

    Hi All,
    I am using jdev 11.1.1.4.0. I am removing the rows from the database using viewobject( quering the viewobject to find the records i want to delete).
    I am using vo.removeCurrentRow(0). Before this statement I am able to get the rows I want to delete.
    after that i am doing am.transaction.commit(). But I am getting the error..
    javax.faces.el.EvaluationException: oracle.jbo.DMLException: JBO-26080: Error while selecting entity for CriteriaEO
         at org.apache.myfaces.trinidadinternal.taglib.util.MethodExpressionMethodBinding.invoke(MethodExpressionMethodBinding.java:58)
         at org.apache.myfaces.trinidad.component.UIXComponentBase.broadcastToMethodBinding(UIXComponentBase.java:1256)
         at org.apache.myfaces.trinidad.component.UIXCommand.broadcast(UIXCommand.java:183)
         at oracle.adf.view.rich.component.fragment.UIXRegion.broadcast(UIXRegion.java:148)
         at oracle.adf.view.rich.component.fragment.ContextSwitchingComponent$1.run(ContextSwitchingComponent.java:92)
         at oracle.adf.view.rich.component.fragment.ContextSwitchingComponent._processPhase(ContextSwitchingComponent.java:361)
         at oracle.adf.view.rich.component.fragment.ContextSwitchingComponent.broadcast(ContextSwitchingComponent.java:96)
         at oracle.adf.view.rich.component.fragment.UIXInclude.broadcast(UIXInclude.java:102)
         at oracle.adf.view.rich.component.fragment.ContextSwitchingComponent$1.run(ContextSwitchingComponent.java:92)
         at oracle.adf.view.rich.component.fragment.ContextSwitchingComponent._processPhase(ContextSwitchingComponent.java:361)
         at oracle.adf.view.rich.component.fragment.ContextSwitchingComponent.broadcast(ContextSwitchingComponent.java:96)
         at oracle.adf.view.rich.component.fragment.UIXInclude.broadcast(UIXInclude.java:96)
         at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl.broadcastEvents(LifecycleImpl.java:879)
         at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl._executePhase(LifecycleImpl.java:312)
         at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:185)
         at javax.faces.webapp.FacesServlet.service(FacesServlet.java:265)
         at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
         at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
         at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:300)
         at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
         at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
         at oracle.adf.model.servlet.ADFBindingFilter.doFilter(ADFBindingFilter.java:205)
         at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
         at oracle.adfinternal.view.faces.webapp.rich.RegistrationFilter.doFilter(RegistrationFilter.java:106)
         at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl$FilterListChain.doFilter(TrinidadFilterImpl.java:446)
         at oracle.adfinternal.view.faces.activedata.AdsFilter.doFilter(AdsFilter.java:60)
         at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl$FilterListChain.doFilter(TrinidadFilterImpl.java:446)
         at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl._doFilterImpl(TrinidadFilterImpl.java:271)
         at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl.doFilter(TrinidadFilterImpl.java:177)
         at org.apache.myfaces.trinidad.webapp.TrinidadFilter.doFilter(TrinidadFilter.java:92)
         at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
         at oracle.adf.library.webapp.LibraryFilter.doFilter(LibraryFilter.java:175)
         at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
         at oracle.security.jps.ee.http.JpsAbsFilter$1.run(JpsAbsFilter.java:111)
         at java.security.AccessController.doPrivileged(Native Method)
         at oracle.security.jps.util.JpsSubject.doAsPrivileged(JpsSubject.java:313)
         at oracle.security.jps.ee.util.JpsPlatformUtil.runJaasMode(JpsPlatformUtil.java:413)
         at oracle.security.jps.ee.http.JpsAbsFilter.runJaasMode(JpsAbsFilter.java:94)
         at oracle.security.jps.ee.http.JpsAbsFilter.doFilter(JpsAbsFilter.java:161)
         at oracle.security.jps.ee.http.JpsFilter.doFilter(JpsFilter.java:71)
         at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
         at oracle.dms.servlet.DMSServletFilter.doFilter(DMSServletFilter.java:136)
         at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
         at weblogic.servlet.internal.RequestEventsFilter.doFilter(RequestEventsFilter.java:27)
         at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
         at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3715)
         at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3681)
         at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
         at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
         at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2277)
         at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2183)
         at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1454)
         at weblogic.work.ExecuteThread.execute(ExecuteThread.java:207)
         at weblogic.work.ExecuteThread.run(ExecuteThread.java:176)
    Caused by: oracle.jbo.DMLException: JBO-26080: Error while selecting entity for CriteriaEO
         at oracle.jbo.server.OracleSQLBuilderImpl.doEntitySelectForAltKey(OracleSQLBuilderImpl.java:1117)
         at oracle.jbo.server.BaseSQLBuilderImpl.doEntitySelect(BaseSQLBuilderImpl.java:553)
         at oracle.jbo.server.EntityImpl.doSelect(EntityImpl.java:8134)
         at oracle.jbo.server.EntityImpl.lock(EntityImpl.java:5863)
         at oracle.jbo.server.EntityImpl.beforePost(EntityImpl.java:6369)
         at oracle.jbo.server.EntityImpl.postChanges(EntityImpl.java:6551)
         at oracle.jbo.server.DBTransactionImpl.doPostTransactionListeners(DBTransactionImpl.java:3275)
         at oracle.jbo.server.DBTransactionImpl.postChanges(DBTransactionImpl.java:3078)
         at oracle.jbo.server.DBTransactionImpl.commitInternal(DBTransactionImpl.java:2088)
         at oracle.jbo.server.DBTransactionImpl.commit(DBTransactionImpl.java:2369)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:597)
         at com.sun.el.parser.AstValue.invoke(Unknown Source)
         at com.sun.el.MethodExpressionImpl.invoke(Unknown Source)
         at org.apache.myfaces.trinidadinternal.taglib.util.MethodExpressionMethodBinding.invoke(MethodExpressionMethodBinding.java:53)
         ... 53 more
    Caused by: java.sql.SQLSyntaxErrorException: ORA-00972: identifier is too long
         at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:457)
         at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:405)
         at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:889)
         at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:476)
         at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:204)
         at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:540)
         at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:217)
         at oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:924)
         at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1261)
         at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1419)
         at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3752)
         at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3806)
         at oracle.jdbc.driver.OraclePreparedStatementWrapper.executeQuery(OraclePreparedStatementWrapper.java:1667)
         at oracle.jbo.server.OracleSQLBuilderImpl.doEntitySelectForAltKey(OracleSQLBuilderImpl.java:869)
    Please give suggestions...
    Thanks
    Kanika

    Hi,
    First Run Application module and confirm whether model project is OK,Cause for the Error is Caused by: java.sql.SQLSyntaxErrorException: ORA-00972: identifier is too long
    check:
    Issues with table/column name length
    identifier is too long
    I guess following error occurred because above issue
    JBO-26080: DMLException
    Cause: An unexpected exception occurred while executing the SQL to fetch data for an entity instance or lock it.
    Action: Fix the cause for the SQLException in the details of this exception.
    See:
    http://download.oracle.com/docs/cd/A97337_01/ias102_otn/buslog.102/bc4j/jboerrormessages.html#26080Hope you will helpful

  • How to get first 10 records from the database using JSP

    i want ot get first 10 records from the database and then after clicking the next button in the page,it must show the next precceding 10 records from the database.i am getting the first 10 records .but how to post to the same page to get another preceeding 10 record.

    Search the forums - this has been asked a lot. I usually recommend experimenting with tops and order bys until you're satisfied.
    Kind regards,
      Levi

  • How to delete record from table control using BDC?

    Hello friends,
    I am running a BDC program to delete records.
    I have file with following records and i got these records into t_itab.
    Material     Plant     Start date     End date     Cost
    MQ100001     S001     09/01/2008     09/31/2008     55.00
    MQ100004     S002     09/01/2008     09/31/2008     56.00
    MQ100008     S003     09/01/2008     09/31/2008     57.00
    Now, I have BDC transaction in which table control screen which contains following structure.
    MQ100001     S001     09/01/2008     09/31/2008     55.00
    MQ100002     S002     09/01/2008     09/31/2008     56.00
    MQ100004     S003     09/01/2008     09/31/2008     47.00     
    MQ100005     S004     09/01/2008     09/31/2008     25.00
    MQ100006     S012     09/01/2008     09/31/2008     76.00
    MQ100007     S033     09/01/2008     09/31/2008     17.00
    MQ100008     S011     09/01/2008     09/31/2008     95.00
    MQ100009     S002     09/01/2008     09/31/2008     46.00
    I have recorded from SHDB in which first record will be delete.
    So, when i loop through t_itab,instead of deleting MQ100001,MQ100004 and MQ100008 from BDC screen,
    it is deleting MQ100001,MQ100002 and MQ100004 (first record for each process ).
    Which i don't want to.
    Is there any facility in BDC to put records on top which i want to delete?
    Please guide me.
    Regards,
    RH

    One option is to identify the table and find out the location as the number of row which should be deleted from the table and then in the bdc program instead of postioning the cursor on the row 1(using the statement perform bdc_cursor ....(01)), replace the 01 with the row number.
    Second option is that if a filter control is available for the table control, then filter the data each and every time with the material number to be deleted and then delete the first row.
    Regards
    Farzan

  • Delete records from internal table using another internal table

    HI,
    I have two internal tables itab1 and itab2 which have same records initially.Later some records of itab2 are deleted .Then i want to delete those records from itab1 also ie,those records not found in itab2 .Is there any method other than looping.
    So that itab1 again becomes equal to itab2.
    Thanks in advance.
    Sowmya.

    Soumya,
    Itab1 , Itab2 .
    Before deleting the records from itab2  move those records to one more internal table itab3.
    Now you have deleted records  of itab2  in itab3.
    SORT ITAB3,ITAB1 by your main key field.
    LOOP AT itab3.
      READ TABLE ITAB1 WITH KEY key field = itab3-
      keyfield.
    IF sy-subrc EQ 0.
    DELETE itab1 where keyfield eq itab3-keyfield.
    ENDIF.
    ENDLOOP.

  • Delete records from multiple table

    Hi,
    I need to delete records from multiple tables using a single delete statement. Is it possible ? If so please let me know the procedure.
    Kindly Help.
    Thanks,
    Alexander.

    Hi Tim,
    Syntax of DELETE statement does not allow for multiple tables to be specified in this way. Infact, none of the DMLs allow you to specify table names like this.
    Technically, there are other ways of deleting from multiple tables with one statement.
    1. "Use a trigger":
    What was probably meant by this is that you have a driving-table on which you create a on-delete trigger. In this trigger, you write the logic for deleting from other tables that you want to delete from.
    This does mean a one-time effort of writing the trigger. But the actual DML operation of deleting from all the tables would be simply triggered by a delete on driving-table.
    2. Dynamic SQL:
    Write a PL/SQL code to open a cursor with table-names from which you want the data to be deleted from. In the cursor-for loop, write a dynamic SQL using the table-name to delete from that table.
    3. Using Foreign-Key constraint with Cascade-Delete:
    This I feel is a more 'cleaner' way of doing this.
    Having to delete data from multiple tables means that there is some kind of parent-child relationship between your tables. These relationships can be implemented in database using foreign-key constraints. While creating foreign-key constraint give the 'on delete cascade' clause to ensure that whenever data is deleted from parent-table, its dependent data is deleted from child-table.
    Using foreign-key constraint you can create a heirarchy of parent-child relationships and still your DELETE would be simple as you would only have to delete from parent-table.
    IMPORTANT: Implementing foreign-key constraints would also impact other DML operations that you should keep in mind.

  • Deleting records from ztable??

    hi there....
    i have arequirement to delete records from a ztable using coding .....
    i hav tried the delete command but its not working properly.
    can anyone suggest a proper method for this....
    urgent requirement.... useful ans wil be rewarded.
    regards'

    DELETE { {FROM target [WHERE sql_cond]}
           | {target FROM source} }.
    PARAMETERS p_carrid TYPE sflight-carrid.
    DELETE FROM sflight
    WHERE  carrid = p_carrid AND
           fldate = sy-datum AND
           seatsocc = 0.
    PARAMETERS p_carrid TYPE sflight-carrid.
    TYPES: BEGIN OF sflight_key,
             mandt  TYPE sflight-mandt,
             carrid TYPE sflight-carrid,
             connid TYPE sflight-connid,
             fldate TYPE sflight-fldate,
          END OF sflight_key.
    DATA sflight_key_tab TYPE TABLE OF sflight_key.
    SELECT carrid connid fldate
           FROM sflight
           INTO CORRESPONDING FIELDS OF TABLE sflight_key_tab
           WHERE carrid = p_carrid AND
                 fldate = sy-datum AND
                 seatsocc = 0.
    DELETE sflight FROM TABLE sflight_key_tab.

  • How to delete the child record from the database

    how to delete a parent and child record from the database can we do it in the servlet and my database is oracle

    I'm not sure I understand the question but you could certainly use the JDBC API from within your servlet to access and modify a DB. You could also use an EJB layer to access your DB and accomplish the same tasks.

  • Problem When deleting record from database

    Hi ,
    I have a question. Firstly I'm using VB
    I have a problem about deleting any record from access database , That's the code I'm use it for add new item and it's work but it's not work when I tried to edit any rows " it's not want to Save" but work for add new Item.
    Try
    Me.Validate()
    Me.CustomerBindingSource.EndEdit()
    Me.CustomerTableAdapter.Update(Me.KonoDataSet.Customer)
    MsgBox("Update Successful")
    Catch ex As Exception
    MsgBox("Update Failed")
    End Try
    And That's my code for Deleting any record from database But it's not work and that's a problem.
    CustomerBindingSource.RemoveCurrent()
    CustomerBindingSource.EndEdit()
    Me.CustomerTableAdapter.Update(Me.KonoDataSet.Customer)
    Can anybody help me about that issue ?

    Hi kono20006000,
    Your issue seems really strange. I would recommend you make a troubleshooting.
    1.Made sure your code works with the single copy of the database. You could check if it scans hard drive for the database file name and check if it modifies dates on found files. You could check if you operate with the same database.
    2. Use the application update the record at the form_load event to see if it would work correctly.
    3.Check the table in update statement and the table in add statement.
    Best Regards,
    Edward
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

  • Moving audit Records from one database to another database using dblink

    i got five database, i have to move sys.aud$ records from five databases to one centralized database into another schema every day at 10:00 clock, i have to use a dblink for this, i have to create same table as sys.aud$ with different schema in centralized database with one extra column db_unique_name,by using db_link how i need to move records from all the five databases to one centralized database, can anyone help me here how to create a db_link from to move records from five database to one centralized database, due to maintainance perspective i have to move the records from all the five databases to one centralized database. i have to write a script for moving the audit records from all the five databases to one centralized database, can anyone help me how to write the script, or if you have any related scripts , can u post here, it will helpful for me.

    spool audit.log
    --"Auditing Initialisation Parameters: check initialization parameter"
    select name || '=' || value from v$parameter where name like '%audit%'
    ---"if auditing is disabled then issue this command and bounce"
    alter system set audit_trail=db,extended scope = spfile
    shutdown immediate
    startup
    create tablespace ORDER_DATA datafile '+DDATA' size 50m;
    create user INFO identified by INFO;
    Grant connect,resource to INFO;
    Alter user INFO quota unlimited on ORDER_DATA;
    create table INFO.ORDER as select * from sys.aud$;
    alter INFO.ORDER add db_unique_name varchar2(50);
    create table INFO.ORDER
    partition by range (Timestamp#)
    subpartition by hash(dbid)
    subpartition template
    (subpartition sp1 tablespace users,
    subpartition sp2 tablespace users)(
    partition p1 values less than (TO_DATE('07/29/2010','MM/DD/YYYY')),
    partition p2 values less than (TO_DATE('07/29/2011','MM/DD/YYYY')),
    partition p3 values less than (MAXVALUE)) tablespace BGORDER_DATA as select * from sys.aud$
    spool off;
    exit
    BEGIN
    DBMS_SCHEDULER.create_job(
    job_name => 'Move Aud$ records',
    job_type => 'PLSQL_BLOCK',
    job_action => 'CREATE OR REPLACE PROCEDURE bgorder_aud
                        AS
                   ts TIMESTAMP;
                   BEGIN
    ts := SYSTIMESTAMP;
    insert into info.order select * from sys.aud$ where timestamp# < ts;
    delete sys.aud$ where timestamp# < ts;
    commit;
    END;
    start_date => TRUNC(SYSDATE) + 22 / 24,
    repeat_interval => 'FREQ=daily;BYHOUR=22;BYMINUTE=0;BYSECOND=0',
    enabled => TRUE,
    comments => 'Move records');
    END;
    /

  • Delete record from the form and from the database

    hi,
    i want delete record from the form and the database ,but the record is only delete from the from !!!
    this is my code :
    if //condition then
    delete_record;
    commit;
    end if ;
    Any solutions ??
    thnx

    You have unique key field(s) on the table you are trying to insert which actually restricts you from inserting the same value again.
    When you are deleting the record and issue commit there is a record to be inserted in the table which is a duplicate that's why you are getting this unique error.
    As oracle is not able to insert your commit fails and stops your deletion of record from table

  • Deleting Record from Database in PHP

    I'm trying to figure out how to delete a record from my
    database. I already have a recordset with my form selected. But
    when I try to add "Delete Record," I can never seem to figure out
    why it won't delete anything when I load the page in a browser, it
    won't even go to the page I told it to go to after it deletes a
    record. My guess is it's what I'm entering in the "Delete Record"
    part of it, any help would be great. Also, my id is primary key if
    that helps. Thanks ahead of time.

    edwin@aw wrote:
    > However, whenever I click on the hyperlink, the link
    will becomes
    >
    http://www.domain.com/www.LinkFromDatabase.com.
    Why it always append the web
    > site's address?? Do I miss something?
    This is happening because your link doesn't begin with
    http://.
    > echo "<a href='$link' target='_blank'> $link
    </a>";
    This should be echo "<a href='
    http://$link' target='_blank'> $link
    </a>";
    David Powers, Adobe Community Expert
    Author, "The Essential Guide to Dreamweaver CS3" (friends of
    ED)
    Author, "PHP Solutions" (friends of ED)
    http://foundationphp.com/

  • Delete old records in oracle database using jobs

    Hi,
    will it be possible to delete old records in oracle database using jobs
    need to delete old records on weekly basis and rebuild my index.
    Thanks!

    933633, While it is possible to do a great deal with the dbms_scheduler your shop should have a scheduler like CA Unicenter that is used to run the application job schedules. Purge jobs should probably be part of the normal application schedule rather than contained in the database, if your shop has a scheduler in use.
    As far as rebuilding the indexes after the purge keep in mind that freshly rebuilt indexes often have to split when inserts are performed due to the fact the compacted index blocks do not have room to hold the newly inserted keys in the appropriate locations. So just because you purge weekly does not automatically mean the indexes should be rebuilt weekly. You need to look at the index key DML pattern and at the total percentage of the index that is held by deleted rows.
    HTH -- Mark D Powell --

  • How to select first several records from a database table by using select?

    Hi,
       I want to select first 100 records from a database table by using select clause. How to write it?
       Thanks a lot!

    hai long!
                 well select statement is used to retrive
    records from the database.
    following is the syntax to be used.
    1) select *  into corresponding fields of itab from basetable where condition.
    endselect.
      ex: select * into corresponding fields of itab from mara
                where matnr >= '1' and  matnr <= '100'.
           append itab.
          endselect.
    select * is a loop statement.it will execute till matnr is less than or equal to 100.
    note: you can also mention the required field names in the select statement otherwise it will select all the field from table mara.
    note: itab means your internal table name.
    hope you got the required thing.if it really solved u r problem then award me the suitable points.<b></b>

  • I need the code to delete record in the database not in the form???

    I need the code to delete record in the database not in the form...
    because when i execute a form always insert the datas in the data base but i want insert value on a text file and delete in the data base the record whith this value of text file.
    i'm spanish an my english is bad sorry.
    thank, javier

    Well, I fail to understand why you want to complicate easy things, but anyway you can do that by using TEXT_IO within Forms to create text file (see Forms builder help), and UTL_FILE package to read it within Pl/Sql : you could create a stored procedure, and call it from Forms passing the file name as parameter. See UTL_FILE documentation

Maybe you are looking for