How do i update a db table using one JSP page

I created a JSP Form page and I want to update a db table when the user hit submit. Please help my job depends on it Send me small code example below is what I have (very new to JSP)
<%@ page language="java" import="java.sql.*" import="java.io.*" %>
<html>
<head><title>accessing database</title></head>
<body bgcolor="white">
<%     Connection con =null;
     try {
// Load Driver Class File
     Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
//Make a connection to Data table
con = DriverManager.getConnection("jdbc:odbc:SportsbookTables", "developer", "developer");
Statement statement =con.createStatement();
String SQL = new String("INSERT INTO tblLines (gameID,leagueType) VALUES (5,'gam')");
statement.executeUpdate(SQL);
statement.executeUpdate("INSERT INTO tblLines (gameID,leagueType) VALUES (6,'lea')");
%>
<table border=1 cellspacing=1 cellpadding=1>
<form method="POST">
<p><font color="#800000" size="5">Enter your name:</font><input name="leagueType" size="4"></p>
<p><input type="submit" value="Submit"></p>
</form>
<%
catch (IOException ioe)
out.println("IO Exception:");
out.println(ioe.getMessage());
catch (SQLException sqle)
out.println("SQL Exception:");
out.println(sqle.getMessage());
catch (ClassNotFoundException cnfe)
out.println("Class Not Found Exception:");
out.println(cnfe.getMessage());
catch (Exception e)
out.println("General Exception:");
out.println(e.getMessage());
finally {
try
if (con!=null) {
con.close();
catch(SQLException sqle)
out.println(sqle.getMessage());
%>
</table>
</Body>
</HTML>

First I would remove all the JDBC code you have in the JSP and place it in a servlet (or other Java) class, and have your form action call the servlet on submission. Then use the servlet API to extract the form data from the request and pass it to the JDBC in the servlet to update the DB. Once complete have it branch to another JSP/HTML to let the user know if they were successful or not.
Take a look at some of the online tutorials as they will be helpful with regards to code examples.
Depending on the size of your project, and deadlines naturally, you may also want to have a look at an MVC architecture and custom tags like Struts from Apache. These can make your job a lot eaiser.

Similar Messages

  • Adding data to multiple tables using one form in Access 2010?

    Hi All,
    I have a access database with two tables and I want to create a single form to enter data into that tables.
    How to adding data to multiple tables using one form in Access 2010?
    I don't have to much knowledge of access database?
    Please help me
    Thanks
    Balaji

    You really don't enter identical data into 2 tables.  You enter dat into one single table, and then you have an unique identifier that maps to another table (you have a unique relationship between two tables). 
    Maybe you need to read this.
    http://office.microsoft.com/en-001/access-help/database-design-basics-HA001224247.aspx
    Think about it this way...  What is you update data in 2 tables, and then the data in one of those tables changes, but the data in the other table does NOT change.  WHOOPS!!  Now, you've got a BIG problem.  For instance, you have a customer
    named Bill Gates.  In one Table you update Bill's address to 1835 73rd Ave NE, Medina, WA 98039 and in the other table you accidentally update Bill's address to 183 73rd Ave NE, Medina, WA 98039.  Now you have 2 addresses for Bill.  Why would
    you want that???  Which is right?  No one knows.  If you have one address, you just have to update one address and if there is a mistake, you just have to update one address, but you don't have to waste time trying to figure out which is right
    and which is wong...and then update the one that is wrong.
    Post back with specific questions.
    Knowledge is the only thing that I can give you, and still retain, and we are both better off for it.

  • I want to update the Custom table using the data available in ITAB.

    Hi,
    I want to updaste the Custom Table which is created by me (Ztable) using the data available in itab.(which i got from defferent standard tables)
    I want to update the custom table using the itab data How is it possible?
    Is any possible by using Modify ?
    DPK.

    example here
    modifying datbase table useing internal table
    advises before updating this datbase table plz lock that table to avoid incosistency
    write the logic for modifying
    Modify the database table as per new dunning procedure
    MODIFY fkkvkp FROM TABLE lt_fkkvkp .
    and finally unlock the table
    example
    *To lock table for further operations
    constants: lc_tabname TYPE rstable-tabname VALUE 'FKKVKP' . "FKKVKP
    CALL FUNCTION 'ENQUEUE_E_TABLE'
    EXPORTING
    tabname = lc_tabname
    EXCEPTIONS
    foreign_lock = 1
    system_failure = 2
    OTHERS = 3.
    IF sy-subrc EQ 0.
    To fetch all the contract accounts for customers of the segment
    Households/SME.
    PERFORM fetch_contract_accounts using lc_tabname .
    ENDIF. " IF sy-subrc EQ 0.
    *wrote the logic
    Modify the database table as per new dunning procedure from internal table
    MODIFY fkkvkp FROM TABLE lt_fkkvkp .
    *unlock the tbale
    CALL FUNCTION 'DEQUEUE_E_TABLE'
    EXPORTING
    TABNAME = uc_tabname .

  • Updating A z table using sap xi

    Hi,
    I am new sap XI would like to update a z table using
    sap xi.The dataset is  a flat file as test exercise.Can
    anyone tell me how to go about it .

    Hi Deepak,
    You can also go for abap proxies (server)
    http://help.sap.com/saphelp_nw04/helpdata/en/86/58cd3b11571962e10000000a11402f/frameset.htm
    Hope it will be helpful.
    Regards
    Suraj

  • How can I update a customized table from a text document?

    Hi,
    I am one sample file. The file is an text document. From this .txt file how can I update a customized table in SAP.
    How can I Update the fields in the Customized table.
    Thanks & Regards,
    NManohar.

    use the Function module GUI_UPLOAD or WS_UPLOAD and give the path and the file name from where the data has to be uploaded. in table parameter give the iternal table
    CALL FUNCTION 'GUI_UPLOAD'
      EXPORTING
        filename                      =
      FILETYPE                      = 'ASC'
      HAS_FIELD_SEPARATOR           = ' '
      HEADER_LENGTH                 = 0
      READ_BY_LINE                  = 'X'
      DAT_MODE                      = ' '
      CODEPAGE                      = ' '
      IGNORE_CERR                   = ABAP_TRUE
      REPLACEMENT                   = '#'
      CHECK_BOM                     = ' '
      VIRUS_SCAN_PROFILE            =
      NO_AUTH_CHECK                 = ' '
    IMPORTING
      FILELENGTH                    =
      HEADER                        =
      tables
        data_tab                      =
    EXCEPTIONS
      FILE_OPEN_ERROR               = 1
      FILE_READ_ERROR               = 2
      NO_BATCH                      = 3
      GUI_REFUSE_FILETRANSFER       = 4
      INVALID_TYPE                  = 5
      NO_AUTHORITY                  = 6
      UNKNOWN_ERROR                 = 7
      BAD_DATA_FORMAT               = 8
      HEADER_NOT_ALLOWED            = 9
      SEPARATOR_NOT_ALLOWED         = 10
      HEADER_TOO_LONG               = 11
      UNKNOWN_DP_ERROR              = 12
      ACCESS_DENIED                 = 13
      DP_OUT_OF_MEMORY              = 14
      DISK_FULL                     = 15
      DP_TIMEOUT                    = 16
      OTHERS                        = 17
    IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    and finally use insert command to update the database table with the data

  • How can i update the ADRT table REMARK field

    How can i update the ADRT table REMARK field
    by using only function modules or BAPI's not by direct update's
    please help me
    i need it urgently

    Hi,
    you can try this code:
        SELECT SINGLE * FROM KNA1 WHERE KUNNR = wa_kunnr.
        IF sy-subrc = 0.
          CLEAR adrct.
          SELECT SINGLE * FROM adrct WHERE addrnumber = kna1-adrnr.
          IF sy-subrc = 0.
            adrct-remark = wa_remark.
            MODIFY adrct.
          ENDIF.
        ENDIF
    best regards,
    Thangesh

  • If record is in application server how do u update the single table

    hi
    could anybody tel me
    if record is in application server how do u update the single table
    by using direct input method

    If your Flash player/plugin is older, the only way is to go to Adobe's site (use Limnos' link) and download the full installer. A .DMG file, which you doubleclick to have it mount on the desktop. Inside is the Flash installer app you doubleclick to run and have it upgrade all. Will need an Admin user account.
    After you've upgraded to the latest & greatest, currently 11.5.502.110, a Flash perfpane will show up in System Preferences, where you can set it to auto-update itself, warn you of new updates or manually check for same.

  • How to select data from a table using a date field in the where condition?

    How to select data from a table using a date field in the where condition?
    For eg:
    data itab like equk occurs 0 with header line.
    select * from equk into table itab where werks = 'C001'
                                                      and bdatu = '31129999'.
    thanks.

    Hi Ramesh,
    Specify the date format as YYYYMMDD in where condition.
    Dates are internally stored in SAP as YYYYMMDD only.
    Change your date format in WHERE condition as follows.
    data itab like equk occurs 0 with header line.
    select * from equk into table itab where werks = 'C001'
    and bdatu = <b>'99991231'.</b>
    I doubt check your data base table EQUK on this date for the existince of data.
    Otherwise, just change the conidition on BDATU like below to see all entries prior to this date.
    data itab like equk occurs 0 with header line.
    select * from equk into table itab where werks = 'C001'
    and <b> bdatu <= '99991231'.</b>
    Thanks,
    Vinay
    Thanks,
    Vinay

  • How to find the columns and tables used in a stored procedure?

    Hi,
    Can someone suggest how to find the columns and tables used within a stored procedure?
    Thanks
    VBK

    For example:
    SQL> create or replace
      2    procedure p1
      3      is
      4          cnt number;
      5      begin
      6          select count(*) into cnt from emp;
      7  end;
      8  /
    Procedure created.
    SQL> select  referenced_owner,
      2          referenced_name
      3    from  dba_dependencies
      4    where owner = 'SCOTT'
      5      and name = 'P1'
      6      and referenced_type = 'TABLE'
      7  /
    REFERENCED_OWNER               REFERENCED_NAME
    SCOTT                          EMP
    SQL> SY.

  • How to join THREE different tables into internal table using one select statement .

    How to join THREE different tables into internal table using one select statement .
    Hi experts,
    I would like to request your guidance in solving the problem of joining the data from three different database tables into one internal table
    Scenario:
    Database tables:
    SPFLI
    SFLIGHT
    SBOOK.
    Table Fields:
    SPFLI - CARRID CONNID COUNTRYFR CITYFRM COUNTRYTO CITYTO
    SFLIGHT - CARRID CONNID FLDATE SEATSMAX SEATSOCC SEATSMAX_C
    SEATSOCC_C SEATSMAX_F SEATSOCC_F
    SBOOK - CARRID CONNID CLASS
    MY INTERNAL TABLE IS IT_XX.
    Your help much appreciated.
    Thanks in advance.
    Pawan.

    Hi Pawan,
    please check below codes. hope it can help you.
    TYPES: BEGIN OF ty_xx,
            carrid     TYPE spfli-carrid   ,
            connid     TYPE spfli-connid   ,
            countryfr  TYPE spfli-countryfr,
            cityfrom   TYPE spfli-cityfrom  ,
            countryto  TYPE spfli-countryto,
            cityto     TYPE spfli-cityto   ,
            fldate     TYPE sflight-fldate ,
            seatsmax   TYPE sflight-seatsmax ,
            seatsocc   TYPE sflight-seatsocc ,
            seatsmax_b TYPE sflight-seatsmax_b,
            seatsocc_b TYPE sflight-seatsocc_b,
            seatsmax_f TYPE sflight-seatsmax_f,
            seatsocc_f TYPE sflight-seatsocc_f,
            class      TYPE sbook-class,
          END OF ty_xx,
          t_xx TYPE STANDARD TABLE OF ty_xx.
    DATA: it_xx TYPE t_xx.
    SELECT spfli~carrid
           spfli~connid
           spfli~countryfr
           spfli~cityfrom
           spfli~countryto
           spfli~cityto
           sflight~fldate
           sflight~seatsmax
           sflight~seatsocc
           sflight~seatsmax_b
           sflight~seatsocc_b
           sflight~seatsmax_f
           sflight~seatsocc_f
           sbook~class
      INTO TABLE it_xx
      FROM spfli INNER JOIN sflight
      ON spfli~carrid = sflight~carrid
      AND spfli~connid = sflight~connid
      INNER JOIN sbook
      ON spfli~carrid = sbook~carrid
      AND spfli~connid = sbook~connid.
    Thanks,
    Yawa

  • How can I update the trigger table?

    I need a insert trigger on a table and also wants to insert the result value in one of its field.
    it gives mutating error........
    so wots the way of updating it? how can i update the same table.

    For example like this (inside the BEGIN/END section of the trigger):
    :NEW.Col2 := :NEW.Col1;
    C.

  • How to find max(time) from table using group by

    how to find max(time) from table using group by
    select var max(time)
              from table
              into (var1, time1)
               where .....
                 group by var.
    it is fetching record which is top in table.
    if u can help?
    regards.

    No this will fetch the maximum time from teh table.
    select var max(time)
    from table xxxx
    into (var1, time1)
    where .....
    group by var.
    Refer this code
    TABLES SBOOK.
    DATA:  COUNT TYPE I, SUM TYPE P DECIMALS 2, AVG TYPE F.
    DATA:  CONNID LIKE SBOOK-CONNID.
    SELECT CONNID COUNT( * ) SUM( LUGGWEIGHT ) AVG( LUGGWEIGHT )
           INTO (CONNID, COUNT, SUM, AVG)
           FROM SBOOK
           WHERE
             CARRID   = 'LH '      AND
             FLDATE   = '19950228'
           GROUP BY CONNID.
      WRITE: / CONNID, COUNT, SUM, AVG.
    ENDSELECT.

  • How to export only the data displayed in table of a jsp page to Excel

    Hi All,
    I want to export only the data that is displayed in the table of a jsp page to excel. But with my current code everything is getting exported to excel.
    <input type="checkbox" name="download" onclick = "form.submit()"/> Export to Excel
    response.setContentType("application/vnd.ms-excel");
    response.setHeader("Content-disposition", "inline; filename=fileName.xls");
    the table is displayed in the jsp using the following code:
    <table cellspacing="2" cellpadding="3" border="1"
    width="100%"> <tr> <%for (int i = 2; i <= cols; i++) {%>
    <td>
    <%
    out.println( rsmd.getColumnName(i) + " ");
    } %>
    <% while (rsettaba.next ())
    out.println("<tr>");
    for (int j= 2; j <= cols ; j++) {
    //out.println("<td>"+rsetallcl.getString(j)+"</td>");
    String varnl = rsettaba.getString(j);
    if ( varnl == null )
    out.println("<td> Empty </td>");
    else
    out.println("<td>"+rsettaba.getString(j)+"</td>");
    out.println("</tr>");
    %>
    </td>
    </tr>
    </table>
    please can anyone help how to just extract only the data in the table of a jsp page to excel.
    Edited by: Ramky48 on Dec 9, 2009 9:51 PM

    Ramky48,
    Why did you open a new thread when you had gotten quite a few responses and suggestions on the [url http://forums.oracle.com/forums/thread.jspa?threadID=998411]thread where you asked the same question - seems the best thing to do would be to continue on the same thread?
    However, your question has nothing to do with JDeveloper/ADF. If you'd like to do it the ADF way, it's trivially easy - you can use the [url http://download.oracle.com/docs/cd/E15523_01/apirefs.1111/e12419/tagdoc/af_exportCollectionActionListener.html]af:exportCollectionActionListener component, which does what you are asking for. If you want to use a straight JSP way, there were several good suggestions in the other thread you opened, or Googling "jsp export to excel" will get you about 4.6 million hits; the first 10 or so look pretty promising.
    John

  • Purchased a second iphone need to create an account, however the computer already has an itunes account...How do I create a second  account using one copy of itunes on a computer??

    Purchased a second iphone need to create an account, however the computer already has an itunes account for the first iphone...How do I create a second  account using one copy of itunes on single computer??

    Why do you need a new account?
    Use the same account on both.
    How to use multiple iPods, iPads, or iPhones with one computer

  • How do I setup multiple users to use one source but manage playlists separately?  For example, play counts are specific to each user.

    How do I setup multiple users to use one source but manage playlists separately?  For example, play counts are specific to each user.

    Hi,
    Thank you for posting in Windows Server Forum.
    Here adding to the words of “Tim”, a forwarder is a DNS server on a network used to forward DNS queries for external DNS names to DNS servers outside of that network. You can also forward queries according to specific domain names using conditional forwarders.
    A DNS server on a network is designated as a forwarder by having the other DNS servers in the network forward the queries they cannot resolve locally to that DNS server. You can refer information regarding forwarders and how to configure from beneath link.
    Understanding forwarders
    http://technet.microsoft.com/en-us/library/cc782142(v=ws.10).aspx
    Configure a DNS Server to Use Forwarders
    http://technet.microsoft.com/en-us/library/cc754941.aspx
    Hope it helps!
    Regards.

Maybe you are looking for