Insert/Delete in a servlet to dbase  - URGENT!!

I have an urgent question. If I use a query to select from values based on a variable from a JSP (subject code)...... and then based on the values returned by this query (i.e code, year and semester,unit) I then want to add/delete these values to a new table (called chosensubject), based on whether they chose the variable drop or add in the JSP!!
How do I do this???
I am using a servlet which picks up the data from a JSP after it is submitted to the server.
Please Help!
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletException;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.DriverManager;
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class loginAssign2 extends HttpServlet
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
//get the parametes from the JSP page
String sem1c1 = request.getParameter("Sem1#1").trim();
String us = request.getParameter("username").trim();
String sem1c2 =request.getParameter("Sem1#2").trim();
String sem1c3 = request.getParameter("Sem1#3").trim();
String sem1c4 = request.getParameter("Sem1#4").trim();
String sem2c1 = request.getParameter("Sem2#1").trim();
String sem2c2 = request.getParameter("Sem2#3").trim();
String sem2c3 = request.getParameter("Sem2#3").trim();
String sem2c4 = request.getParameter("Sem2#4").trim();
String userID = request.getParameter("userID").trim();
String Drop1 = request.getParameter("drop1").trim();
String Drop2 = request.getParameter("drop2").trim();
String Drop3 = request.getParameter("drop3").trim();
String Drop4 = request.getParameter("drop4").trim();
String Drop5 = request.getParameter("drop5").trim();
String Drop6 = request.getParameter("drop6").trim();
String Drop7 = request.getParameter("drop7").trim();
String Drop8 = request.getParameter("drop8").trim();
String sqlQuery;
String sqlQuery2;
if (sem1c1 !="") {
sqlQuery = "select*from tmpoffering where code = '" + sem1c2 + "'";
// Iterate through the result and verify the password
response.setContentType("text/html");
PrintWriter out = response.getWriter();
Connection conn = null;
try {   
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection("jdbc:oracle:thin:@Midas2:1521:globaldb", "system", "manager");
catch (Exception e) {
out.println("Cannot close connect to database!"+e);
if (conn != null) {
try { // execute the query
Statement stmt = conn.createStatement();
ResultSet rst;
rst = stmt.executeQuery(sqlQuery);
// Fetch the query result, and dispaly them in a table
while (rst.next()) {
<<Need help here!!!! Think I need an if statement (i.e if 'drop' then delete otherswise if 'add' then insert!!!... but how do I put it into a servlet??)
     sqlQuery2 = "insert into subjectchoosen values ('code','year','sem','userID') ";
stmt.close();
} catch(Exception e) {
     out.println("Cannot fetch data from database!"+e);
out.println("</table>");
out.println("</body></html>");

If the servlet is within an application container,
you can locate a data source create a SQL connection an execue a query.
DataSource ds =  (DataSource) (new InitialContetx()).lookup("my_ds");
Connection conn = ds.getConnection();if it is only a web server
/** sample using JSQLDriver */
Connection conn = null;
Statment stmt = null;
ResultSet rs = null;
try {
  Class.forName("com.jnetdirect.jsql.JSQLDriver");
  conn = DriverManager.getConnection(
          "jdbc:JSQLConnect://localhost/database=master",
          "sa",
  stmt = conn.createStatement();
  rs = stmt.executeQuery("select * from my_table");
} finally {
  try {
    if (rst != null) {
      rs.close();
    if (stmt != null) {
      stmt.close();
    if (conn != null) {
        conn.close();
  catch (SQLException ex2) {
}

Similar Messages

  • Update/insert/delete data from xcelsius to Database via web service

    Hi,
    I need to create dashboard that go function can <b>update/insert/delete</b> data send to <u>Database</u> thru <u>web services</u>, as i know got 2 xcelsius add-on software which support those of function <b>InfoBurst</b> and <b>flynet </b>
    <b>InfoBurst</b>
    http://www.infosol.com/azbocug/minutes/4-Writeback%20to%20a%20Database%20with%20Xcelsius.pdf
    <b>flynet </b>
    http://www.flynetviewer.com/public/community/Blogs/FlynetXcelsiusServerUser/default.aspx
    Except this 2 purchase add-on xcelsius, any other solution ?  
    Maybe need to write some in MSSQL or C# programming which enable insert, update, delete ...etc  ?
    *note: i not use Xcelsius Engage Server , i use Xcelsius Engage only
    thanks,
    regards
    s1
    Edited by: Leong Pui Kee on Mar 1, 2011 6:06 AM

    Hi,
    As of now in Xcelsius/Dashboard Design there is no feature or functionality to insert/update/delete data from database.
    Solution:
    Create a Web service in let’s say C# or Java, which will perform insert/update/delete operation.
    In Xcelsius add Web Service connection and user above web service.
    Xcelsius Web Service connection provides option to pass input values to a Web Service (Input Pane) and get the result (Output values pane).
    We can pass values to be written to the database as a input to Web Service via Web Service connection from Xcelsius and write data to the database.
    Note:
    Performing delete operation from Xcelsius Dashboard could be risky and may delete important data from database. I would not prefer giving delete option/functionality in Xcelsius dashboard.
    Hope this helps!
    Thank you.
    Regards,
    Vinay Mhaske

  • How to remove the the standard button APPEND/INSERT/DELETE in webdynpro alv

    Hello,
    how to remove the the standard button APPEND/INSERT/DELETE in webdynpro-abap  alv
    Thanks
    Rakshar

    Use  this.
        data lo_cmp_usage type ref to if_wd_component_usage.
        lo_cmp_usage =   wd_this->wd_cpuse_alv1( ).
        if lo_cmp_usage->has_active_component( ) is initial.
          lo_cmp_usage->create_component( ).
        endif.
        data lo_interfacecontroller type ref to iwci_salv_wd_table .
        lo_interfacecontroller =   wd_this->wd_cpifc_alv1( ).
        data lo_value type ref to cl_salv_wd_config_table.
        lo_value = lo_interfacecontroller->get_model(
        data: lr_std type ref to if_salv_wd_std_functions.
        lr_std ?= lo_value.
        lr_std->set_export_allowed( abap_false ).
    NOte: ALV1 is alv component name
    Regards
    Srinivas
    Edited by: sanasrinivas on Dec 1, 2011 6:11 AM

  • How do I insert/Delete/Update a row to the DB Table from Business Component Browser

    I am using the wizard and created a project containing Business component which contain some table.
    When I run the project I could see "Oracle Business Component Browser(local)" and when I select some table from "View Object Member" I get a window displaying all the field of that table and I could browse all the info.
    My Problem is when I try to insert a new record/Delete the existing record or update some record it never gets reflected to the DataBase.
    When I try to insert a new row I did save and there was a dialog box displayed saying "Transaction ID is 1". But finally It's not reflected in the Database.
    Can some one guide me how can I do insert/delete/update operation from Oracle Component Business Browser so that the changes reflect to the Original DataBase.
    Thanks in advance
    Jitendra

    Jitendra,
    This may be a problem of caching. If you do an update,insert, or delete, and do not receive an error, then the transaction should indeed be posted.
    I assume you are hitting the Save icon after your changes if you are getting a transaction ID. Are you checking for the updates through another session (i.e. SQL*Plus), or do you then requery the View Object in the tester? Do you exit the tester and come back in and not see the changes?

  • Inserting/ deleting a line item in MIGO Transaction ( Goods Issue )?

    Hi,
    Can anyone help me with the logic for Inserting / deleting a line item in MIGO Transaction?
    Thanks,
    cs

    Hi
    The following user exits and badis for migo:
    Check the mb_migo_badi and check the method 'LINE_MODIFY' for u r purpose.
    For undestanding see the documentation of the badi and see the example implementation
    class: CL_EXM_IM_MB_MIGO_BADI
                                                                                    Enhancement/ Business Add-in            Description                                                                               
    Enhancement                                                                               
    MB_CF001                                Customer Function Exit in the Case of Updating a Art. Doc.      
    MBCF0011                                Read from RESB and RKPF for print list in  MB26                 
    MBCF0010                                Customer exit: Create reservation BAPI_RESERVATION_CREATE1      
    MBCF0009                                Filling the storage location field                              
    MBCF0007                                Customer function exit: Updating a reservation                  
    MBCF0006                                Customer function for WBS element                               
    MBCF0005                                Article document item for goods receipt/issue slip              
    MBCF0002                                Customer function exit: Segment text in article doc. item                                                                               
    Business Add-in                                                                               
    MB_RESERVATION_BADI                     MB21/MB22: Check and Complete Dialog Data                       
    MB_QUAN_CHECK_BADI                      BAdI: Item Data at Time of Quantity Check                       
    MB_PHYSINV_INTERNAL                     Connection: Core Inventory and Retail AddOn                     
    MB_MIGO_ITEM_BADI                       BAdI in MIGO for Changing Item Data                             
    MB_MIGO_BADI                            BAdI in MIGO for External Detail Subscreens                     
    MB_DOC_BADI_INTERNAL                    BAdIs when Creating an Article Document (SAP Internal)          
    MB_DOCUMENT_UPDATE                      BADI when updating article document: MSEG and MKPF              
    MB_DOCUMENT_BADI                        BAdIs when Creating an Article Document                         
    MB_CIN_MM07MFB7_QTY                     Proposal of quantity from Excise invoice in GR                  
    MB_CIN_MM07MFB7                         BAdI for India Version exit in include MM07MFB7                 
    MB_CIN_LMBMBU04                         posting of gr                                                   
    MB_CHECK_LINE_BADI                      BAdI: Check Line Before Copying to the Blocking Tables          
    ARC_MM_MATBEL_WRITE                     Check Add-On-Specific Data for MM_MATBEL                        
    ARC_MM_MATBEL_CHECK                     Check Add-On-Specific Criteria for MM_MATBEL    
    If it is helpfu rewards points
    Regards
    Pratap.M

  • Insert,  Delete and Update options in Table control

    Experts,
    I have writen code for Insert,  Delete and Update options in Table control. They are not working properly...
    can any one send the code for the above please...
    Thanks in advance..

    Hi,
    Following steps will help you.
    1.TOP-INCLUDE
    DATA: ITAB1 LIKE KNA1 OCCURS 0 WITH HEADER LINE.
    DATA: ITAB2 LIKE KNA1 OCCURS 0 WITH HEADER LINE.
    DATA: WA LIKE KNA1.
    DATA: ANT TYPE I,CUR TYPE I.
    DATA: OK_CODE TYPE SY-UCOMM.
    CONTROLS: TABCTRL TYPE TABLEVIEW USING SCREEN 100.
    IN FLOWLOGIC
    PROCESS BEFORE OUTPUT.
    LOOP AT ITAB1 CURSOR CUR WITH CONTROL TABCTRL.
    ENDLOOP.
    PROCESS AFTER INPUT.
    MODULE CLEAR_DATA.
    LOOP AT ITAB1.
    MODULE MOVE_DATA.
    ENDLOOP.
    ADD “OK_CODE” IN ELEMENT LIST. CLICK ON LAYOUT AND  ADD TABLE CONTROL(name it as TABCTRL) AND PUSHBUTTONS AS FOLLOWS.
    SELECT THE FIELDS FROM PROGRAM. SAVE CHECK AND ACTIVATE.
    CLICK ON FLOWLOGIC EDITOR FROM APPLICATION TOOL BAR.
    DOUBLE CLICK ON MODULE “CLEAR_DATA”.
    write the in this module as below.
    CLEAR ITAB2. REFRESH ITAB2.
    DOUBLE CLICK ON MODULE “MOVE_DATA”.
    write the code in this module as below.
    APPEND ITAB1 TO ITAB2.
    ACTIVATE PAI AND WRITE THE CODE AS BELOW.
    CASE OK_CODE.
    WHEN 'FETCH'.
    SELECT * FROM KNA1 INTO TABLE ITAB1 UP TO 20 ROWS.
    TABCTRL-LINES = SY-DBCNT.
    WHEN 'ADD'.
    GET CURSOR LINE CNT.
    CNT = TABCTRL-TOP_LINE + CNT - 1.
    CLEAR WA.
    INSERT WA INTO ITAB1 INDEX CNT.
    WHEN 'MODIFY'.
    GET CURSOR LINE CNT.
    READ TABLE ITAB2 INDEX CNT.
    LOOP AT ITAB2.
    MODIFY KNA1 FROM ITAB2.
    ENDLOOP.
    SELECT * FROM KNA1 INTO TABLE ITAB1.
    WHEN 'EXIT'.
    LEAVE PROGRAM.
    ENDCASE.
    SAVE,CHECK AND ACTIVATE ALL.
    CREATE TCODE AND EXECUTE.
    contact if u hv any issues regarding this code.
    reward points,if it is useful.
    Thanks,
    Chandu.

  • Oracle Auditing for Insert/delete in a Table

    Dear Oracle Guru's
    I have a Master table for which records are added manually using the Insert command and not by any front end tools.
    I have no Auditing for this table , like when an insert/delete is made in to this table.
    Does oracle provides any other Tables/views like v$session to find out when such events happens.
    Kindly guide me
    With Warm Regards
    ssr

    Probably not.
    If your database is in ARCHIVELOG mode and you have the archived logs from the point in time that the DML happened, you could potentially use LogMiner to read the redo logs and get information about when the DML happened and who was responsible. That tends, however, to be a relatively painful manual process that is frequently complicated by the fact that most shops get rid of archived logs as soon as they are no longer necessary for database recovery which is frequently a matter of days or weeks.
    Justin

  • Insert delete or update entry in Custom table from KONV entry changed

    Hi All,
    I have custom table ZKONV with only few required columns and should have same number of records as KONV has at any point in time.
    KONV is a cluster table so its not readable from ORACLE level. So ZKONV is created. But I dont know how to keep these both tables in sync.
    I need to perform insert delete or update entry in Custom table if insert delete or update happens on cluster table KONV from any transactions.
    As KONV is a cluster table and does not have changed time stamp I am not able to know the number of records changed in perticulat time period.
    Thanks,

    Thanks for reply,
    There is a Outside SAP system which needs to read KONV data to feed into their system, but as KONV is cluster table they are not able to read it from ORACLE level.
    To solve this we are thinking to create a transparent Z-table and will fill it with KONV and catch Update, delete or Insert statement and do same on ZKONv.
    Is this possible some how? by some database event or something....

  • ALV Operations like Insert,Delete,Change

    Hi all,Iam using 'REUSE_ALV_GRID_DISPLAY',my client want Insert/Delete/Change functionalities in my output.How to achive this? Any example?
    Please dont provide examples with classes,I want to do it with 'REUSE_ALV_GRID_DISPLAY' only.

    Check this program for reference to know how to change values
    BCALV_FULLSCREEN_GRID_EDIT
    Cheers,
    Kothand

  • Single Page Spry Tabbed Insert - Delete - Update

    Hi Guys
    I like to make a page with three Spry Tabs.
    * Using ( PHP - Mysql )
    * Example ( Table of "Users" Fields ID, Name, Age )
    ( First Tab )
    List of all people with navigation dividing table by ten rows
    each time.
    On each row Delete & Update This person.
    When Clicked on Delete [ Delete This Person and update the
    list ]
    When clicked on Update [ Go to third tab and update this
    exact person ]
    ( Second Tab )
    Insert new person to Mysql
    ( Third Tab )
    Update the person who was send here to be updated from tab
    one
    Can I have all list - Insert - Delete - Update in one page
    under different Spry Tabs? How can I send these info from one tap
    to another. How should I go about this?

    It was never possible to have more than one of those
    behaviours on a page
    using the standard behaviours in previous versions. You
    always had to write
    your own scripts.
    Paul Whitham
    Certified Dreamweaver MX2004 Professional
    Adobe Community Expert - Dreamweaver
    Valleybiz Internet Design
    www.valleybiz.net
    "Sanj" <[email protected]> wrote in message
    news:enjulr$qma$[email protected]..
    > Hi,
    >
    > Prior to Dreamweaver 8.02 it was possible to have more
    than 1
    > Insert/delete/update however this is no longer the case
    - is there a way
    > around this?
    >
    > Thanks!
    >
    > Sanj
    >

  • Insert/delete single cells

    This is a wicked dumb question ... I have a fairly large table of data, and I want to line up the entries in one column with the entries in another. What I need to do is easily insert and delete individual cells? I can insert and delete rows ... I need to insert/delete individual cells.

    Many thanks for the helpful tips. I too had the exact question. The "mark for move" technique works just as expected. Yet, I still cannot delete a single empty cell and have the column move upward one cell. After completing shift-command-x and shift-command-v on a single empty cells leaves an empty cell in the source destination. I wanted to delete it. My spreadsheet was small enough to shift blocks of cells upwards using "mark for move" until all the empty cells were at the bottom, whereby I then evoked the delete rows method. It worked but a bit kludgy. Better than before though as I hadn't used the "mark for move",
    I'm using Numbers 09 on a Jan 2010 MBP running Mac OS X 10.6.7
    regards,
    Michael

  • Stored proecedure tutorial for insert, delete, update,select

    I want to integrate the stored procedure in my project
    i am using jsp,
    any one suggest me, stored proecedure tutorial for insert, delete, update,select
    thanx.

    Whether you are using JSP or not should not affect your decision (though I would recommend checking out the MVC pattern, and recommend against doing data access code from your JSP's).
    You simply need one tutorial on how to invoke a stored procedure. The stored procedure you write can have INSERT, SELECT, UPDATE, DELETE, whatever. You simply have to master the concepts involved in java.sql.CallableStatement. (And then you can get more fancy with vendor-specific extensions).
    However, I am a bit confused. You want a tutorial on stored procedures, but then you indicate very normal DML statements like INSERT, UPDATE and DELETE. All of these (queries, DML and stored procedures) fall under the general umberella of JDBC. So, it is always a good place to start with a plain ole JDBC tutorial.
    java.sun.com/docs/books/tutorial/jdbc/index.html
    www.onjava.com/pub/a/onjava/2003/08/13/stored_procedures.html
    - Saish

  • Remove standard button in ALV LIKE APPEND/INSERT/DELETE

    Hi Expert,
    I have a requirement in which we do not need APPEND/INSERT/DELETE button in ALV,Can you please tell how i can remove that.
    Pleaae suggest.
    Thanks
    Mahesh

    Check this
        data lo_cmp_usage type ref to if_wd_component_usage.
        lo_cmp_usage =   wd_this->wd_cpuse_alv1( ). " alv1 is my used alv component
        if lo_cmp_usage->has_active_component( ) is initial.
          lo_cmp_usage->create_component( ).
        endif.
        data lo_interfacecontroller type ref to iwci_salv_wd_table .
        lo_interfacecontroller =   wd_this->wd_cpifc_alv1( ).
        data lo_value type ref to cl_salv_wd_config_table.
        lo_value = lo_interfacecontroller->get_model(    ).
    data: lr_std type ref to if_salv_wd_std_functions.
        lr_std ?= lo_value.
    lr_std->SET_EDIT_APPEND_ROW_ALLOWED( abap_false ).
    lr_std->SET_EDIT_DELETE_ROW_ALLOWED( abap_false ).
    lr_std->SET_EDIT_INSERT_ROW_ALLOWED( abap_false ).
    Regards
    Srinivas

  • Insert,delete,update in oracle Rac11g2

    hi all.
    i am using oracle grid 11g R2,oracle database 11g R2 and oracle Linux Enterprise 5.5.
    i tried to use insert,update and delete in oracle Rac but wihout commit iit did not delete,update and insert in Node2.
    plz can anyone help me that how to insert,delete and update without issuing commit in node1 and perform the action
    on node2 as well?
    Kelly

    Hi Kelly,
    Now I get it, but unfortunately there is no way to do it. TAF can allow only session failover, or query failover (a running query will continue in the other node). But anyway, there is no way to failover a transaction. The transaction will be rolled back automatically (no question or any other option) and the session will get an error. However, the session will be connected to the other node and can continue working or retry the operation.
    HTH
    Liron

  • What's the exact trigger for when updating/inserting/deleting data from one DB to another DB which contains same info?

    Hi guys,
    I have created a copy of the AdventureWorks2012 DB called AdventureWorks2012_new on the same instance.
    I have created the following trigger below but my friend who is a DBA told me that this is not correct and I should be using the inserted table when creating this trigger. I would like AdventureWorks2012_new DB to be updating/inserting/deleting data from
    the same tables that have been updated/inserted/deleted in the AdventureWorks2012 DB. How exactly should I do this for all the tables in the whole database ? What I have written below is just for one of the tables, is there a quicker way to do it for all tables
    in this DB so that it performs the actions mentioned above, automatically ? Help would be greatly appreciated so I can understand how this works, thanks
    CREATE TRIGGER [HumanResources].[tr_HumanResources_AfterUpdate]
    ON [AdventureWorks2012].[HumanResources].[Department]
    AFTER UPDATE
    AS
    BEGIN
    SET NOCOUNT ON;
    UPDATE AdventureWorks2012_new.HumanResources.Department
    SET Name = t2.Name,
    GroupName = t2.GroupName,
    ModifiedDate = t2.ModifiedDate
    FROM AdventureWorks2012.HumanResources.Department AS t2
    INNER JOIN AdventureWorks2012_new.HumanResources.Department AS t1
    ON t2.DepartmentID = t1.DepartmentID
    END

    For insert it's easy:
    CREATE TRIGGER [HumanResources].[tr_HumanResources_AfterInsert]
    ON [AdventureWorks2012].[HumanResources].[Department]
    AFTER INSERT
    AS
    BEGIN
    SET NOCOUNT ON;
    Insert INTO AdventureWorks2012_new.HumanResources.Department
    (DepartmentID, Name, GroupName, ModifiedDate)
    SELECT DepartmentID, Name, GroupName, ModifiedDate
    FROM Inserted;
    END
    I didn't verify column names, so you may need to make sure to use correct column names for that table.
    Setting replication is a bit advanced topic although BOL is clear and you may start here
    http://technet.microsoft.com/en-us/library/ms151198.aspx
    If it will be complicated for you, you can ask extra questions in the MSDN Replication forum.
    For every expert, there is an equal and opposite expert. - Becker's Law
    My blog
    My TechNet articles

Maybe you are looking for

  • Block incoming calendar / meeting requests to a specific mailbox / user using transport rules or an Outlook rule?

    I have a weird request I have never thought I would get. I have a VIP user that wants to receive no calendar invites / meeting invites from: - anyone outside of our organization (ie: from the internet) - only certain users from INSIDE our organizatio

  • Lync 2013 Display photos do no display correctly internally

    Hey guys, really need some help with this one so I will provide as much detail as possible (sorry for the lengthy post): We have Lync 2013, Exchange 2010 and AD is at a 2003 functional level. We are experiencing issues where Lync photos are not updat

  • Using rxvt-unicode as an application launcher

    So I followed the wiki and have the following command bound to Super+BackSpace: $ urxvt -geometry 80x3+480+320 -name 'bashrun' -e sh -c "/bin/bash -i -t" The niggle I'm having is that the window is still open even after I've launched chromium or what

  • Selection screen for submit in BSP

    Hi Experts, I have gone throught the link to submit the program in BSP using varients, but i even want to see the selection screen for tht so tht user can post his own values over there. I tryed SUBMIT with different options but i am not able to see

  • Screen Sharing Broken - Shared Computer Half Ghost/Half Real

    I am trying to screen share into a computer on my local network called "Autumn's Mini." It appears both in the sidebar and the Network window in the Finder. Both File Sharing and Screen Sharing are enabled on the mini, and permissions are set correct