Updating a table via a gui program

i am trying to update a record via the UPDATE function. My program has a show all button that brings in all the records. When i make a change in the record and click Update. I get the error: Syntax error in string in query expression ''00000' the zeroes represent an updated zipcode. Here is my source code for the update function:
if(e.getActionCommand().equals("Update"))
String url = "jdbc:odbc:coffee";
String driver= "sun.jdbc.odbc.JdbcOdbcDriver";
Connection con= null;
Statement stmt =null;
//PreparedStatement stmt = null;
ResultSet my_result= null;
/* String query = "Update CoffeeSuppliers set " +
"Name='" + comp_Name.getText() +
"', Address='" + comp_Addr.getText() +
"', City ='" + comp_City.getText() +
"', State='" + comp_State.getText() +
"', ZipCode='" comp_zipcode.getText()
"' WHERE ID=" + comp_ID.getText();
String query= "Update CoffeeSuppliers set " +
"ID='" + comp_ID.getText() +
"', Name='" + comp_Name.getText() +
"', Address='" + comp_Addr.getText() +
"', City='" + comp_City.getText() +
"', State='" + comp_State.getText() +
"', ZipCode='" + comp_zipcode.getText();
try
Class.forName(driver);
catch(java.lang.ClassNotFoundException exception)
System.err.print("ClassNotFoundException: ");
System.err.println(exception.getMessage());
try
con = DriverManager.getConnection(url,"app","app");
stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
my_result= stmt.executeQuery(query);
stmt.executeUpdate(query);
while(my_result.next())
System.out.println("am i in the while loop");
my_result.updateString(1,comp_ID.getText());
my_result.updateString(2,comp_Name.getText());
my_result.updateString(3,comp_Addr.getText());
my_result.updateString(4,comp_City.getText());
my_result.updateString(5,comp_State.getText());
my_result.updateString(6,comp_zipcode.getText());
my_result.updateRow();
stmt.close();
con.close();
catch(SQLException sqlex)
System.err.println("ERROR: " + sqlex.getMessage());
} //end of the if statement
Any feedback will be great.
thanks

String query= "Update CoffeeSuppliers set " +
"ID='" + comp_ID.getText() +
"', Name='" + comp_Name.getText() +
"', Address='" + comp_Addr.getText() +
"', City='" + comp_City.getText() +
"', State='" + comp_State.getText() +
"', ZipCode='" + comp_zipcode.getText() + "'";I think that it is as simple as the fact that you diddn't close the zipcode string literal being passed to the SQL interpreter. Add the closing ' to the query
Hope this helps,
Bamkin

Similar Messages

  • Updating database table via program

    Hi,
    I am updating a DB table (Sap standard table) via my program.
    I have few doubts with regard to same. They are given below,
    1.  I came to know that it is not best practise to update the sap standard table via program using "update" statement. Why so? Is there any other way or statement in doing the same?
    2.  The sap standard table which i update via my program is BDRGIN. Now my question is, when my  program is modifying the values of the table, if some other user also modifies the value at the same time via SE16 then conflict occurs. How to resolve it? Is SAP uses any automatic handling for such conflicts?
    kindly help me out.
    Regards,
    Raghavendraprasad.N

    Hi,
    Its not a good practise to modify the Standards tables through programs, because most of the standard tables will be interdependant with forign key relation ships (check table relations). So incase we create an irrelavant entry, then it will cause a lot of confusions.
    For example we create entries in MARA/MAKT table using MM01/02 transactions.
    There are a few standard tables like TVSA (containing customising data), these have to be maintained through the SPRO transaction. You can open SPRO transaction and search for the node to maintain entries in it or you can go to the transaction SM30 and you can give the table name and click on customizng to go the SPRO node.
    Still if you are trying to create entries in your table, Enque/Lock the table do the updations and then Deque/Unlock the table, so that there will be no conflicts happening during that time.
    Regards,
    S.Dakshna Nagaratnam.

  • Updating a table via form

    Hello -
    I'm trying to do what (should) be an easy task, but i'm
    pulling out what's left of my hair. I can't seem to update an
    Access table.
    tble_message has the following fields:
    messagesID : autonumber/key
    to [data type number]
    from [data type text]
    Date [data type Date/Time]
    message [data type text]
    time [data type Date/Time]
    I created the following form:
    - - - begin form.cfm - - -
    <FORM
    ACTION="input2.cfm?newcall2=YES&toID=#URLEncodedFormat(toID)#&budName=#URLEncodedFormat(b udname)#"
    Method=Post>
    <INPUT TYPE="hidden" NAME="to"
    VALUE=<cfoutput>#toID#</cfoutput>>
    <INPUT TYPE="HIDDEN" NAME="from"
    value=<cfoutput>"#LoginName#"</cfoutput>>
    <INPUT TYPE="hidden" NAME="DATASOURCE" VALUE="testdb">
    <INPUT TYPE="hidden" NAME="TABLENAME"
    VALUE="tbl_Messages">
    Message to: <cfoutput>#budName#</cfoutput>
    <TEXTAREA NAME="YMESSAGE" ROWS="5" COLS="40"
    WRAP="Virtual"></TEXTAREA>
    <INPUT TYPE="Submit" VALUE="send message">
    <INPUT Type="reset" Value="start again">
    </form>
    - - - end form.cfm - - -
    this form feeds input2.cfm
    - - - begin input2.cfm - - -
    <cfoutput>
    #message#
    #toid#
    #loginName#
    </cfoutput>
    <cfquery name="addmess" DATASOURCE="testdb">
    Insert Into tbl_Messages
    (message,to,from)
    Values
    ('<cfoutput>#message#</cfoutput>','<cfoutput>#toid#</cfoutput>','<cfoutput>#loginName#</c foutput>'
    </CFQUERY>
    - - - end input2.cfm - - -
    i do see the expected values in my cfoutput:
    <cfoutput>
    #message#
    #toid#
    #loginName#
    </cfoutput>
    = = = error message = = =
    I am getting an Error Executing Database Query
    [Macromedia][SequeLink JDBC Driver][ODBC Socket][Microsoft]
    [ODBC Microsoft Access Driver] Syntax error in Insert Into
    statement
    the error occurred in c:\.... input2.cfm: line 21
    20 Values
    21
    ('<cfoutput>#message#</cfoutput>','<cfoutput>#toid#</cfoutput>','<cfoutput>#loginName#</c foutput>')
    22 </CFQUERY>
    = = = end error message = = =
    Form Fields:
    fieldnames:to,from,datasource,tablename,ymessage
    from=chancho2000
    tablename=tbl_messages
    to=100
    ymessage=testing the input form
    url parameters:
    newcall2=yes
    toID=
    .. i just can't seem to populate the database
    any help or direction would be appreciated.. thanks!
    dieg0

    dieg02000 wrote:
    > .. i just can't seem to populate the database
    What is happening? Are you receiving an error, if so what is
    the full error message?
    > <cfquery name="addmess" DATASOURCE="ritmo2000">
    > Insert Into tbl_Messages
    > (message,to,from)
    > Values
    >
    ('<cfoutput>#message#</cfoutput>','<cfoutput>#toid#</cfoutput>','<cfoutput>#loginName#</c foutput>'
    > )
    I do not use Access but FROM is almost certainly a reserved
    keyword and should not be used as a column name. Try renaming it. I
    do not know about the other column names like "To".
    Though it may not cause an error the <cfoutput> tags
    are not needed and should be removed. The #variables# should be
    evaluated automatically. Also consider scoping your variables to
    avoid conflicts and using cfqueryparam. Something like
    <cfquery name="addmess" DATASOURCE="ritmo2000">
    Insert Into tbl_Messages (message, to, TheRenamedFromColumn)
    Values
    <cfqueryparam value="#form.message#"
    cfsqltype="cf_sql_varchar">,
    <cfqueryparam value="#toid#"
    cfsqltype="cf_sql_integer">,
    <cfqueryparam value="#loginName#"
    cfsqltype="cf_sql_longvarchar">

  • Updating a table via an insert statement

    Can someone please assist me with this code. I am attempting to insert into a table through another table. Can anyone see what is wrong with this code?
    insert into passwd_verify select user_id, user_name, first_name,
    last_name, creation_date, email_address
    from(select int_contactid, str_userid, str_fname,
    str_lname, sysdate, str_email
    from tbl_contact
    where int_contactid = '201')
    where passwd_verify.user_id <> tbl_contact.int_contactid;

    or something like:
    insert into passwd_verify
      select tbl_contact.int_contactid user_id,
             tbl_contact.str_userid    user_name,
             tbl_contact.str_fname     first_name,
             tbl_contact.str_lname     last_name,
             tbl_contact.sysdate       creation_date,
             tbl_contact.str_email     email_address
        from tbl_contact,
             passwd_verify
       where int_contactid = '201'
         and passwd_verify.user_id <> tbl_contact.int_contactid
    -- OR --
    insert into passwd_verify
      select tbl_contact.int_contactid user_id,
             tbl_contact.str_userid    user_name,
             tbl_contact.str_fname     first_name,
             tbl_contact.str_lname     last_name,
             tbl_contact.sysdate       creation_date,
             tbl_contact.str_email     email_address
        from tbl_contact
       where int_contactid = '201'
         and tbl_contact.int_contactid not in (select user_id
                                                 from passwd_verify)note: not tested.

  • How to update S Tables (like S812) ?

    Hi
    I need to update some FI tables like S812 in a Z program.
    I see some Z programs wich update directly the S812 table but it supose it's not correct because these tables are like stantard SAP tables wich can only be updated by standard SAP functions.
    In a Z program i need to create some records in these S812 table, does somebody knows how can i update this table ? Is there some FM wich i can use in order to do not update this table directly in Z program ?
    Thanks
    Frank

    Hi ,
    i'm not sure of FI , but i know them in modules like SD , its called Evaluation Structures, u can also see them under path ->Logistics->SD-->Sales Info Systems->Flexi analyses, can ask ur SD guys to give u more details on it.
    regards
    Prabhu

  • Updating ECMCC table

    Hi,
    when i am trying to update glaccount field in ECMCC table  based on glaccount of ECMCT table it is throwing error.
    is there any specific method to update ECMCC table.
    code in the program is :
    loop at it_ecmct.
      update ecmct from it_ecmct.
      if sy-subrc ne 0.
        v_err = v_err + 1.
      else.
    update ecmcc
           set ZZGL_AC = it_ecmct-ZZGL_AC
           where objnr = it_ecmct-COBJNR.
        v_suc = v_suc + 1.
      endif.
    endloop.
    in the above code ECMCT is updating fine but ECMCC is not updating some of the records.
    please let me know how to pass values to update ECMCC table
    Regards,
    Sateesh.
    Edited by: sateesh kumar on Jul 14, 2011 5:55 PM

    Hi ,
    Plz provide me answer if any body faces same situvation with ECMCC table
    is there any specific method to  update ECMCC table
    Regards,
    Sateesh.
    Edited by: sateesh kumar on Jul 22, 2011 1:35 PM

  • Updating a table with need of table joins

    Hi,
    I want to update a table (via PL/SQL process) but to do it I need to include joins - and my code throws an error...
    How would I go about getting this to work?
    UPDATE employees a, action b
    SET a.met_employee = '0000'
    WHERE b.date_met NOT BETWEEN QA1 AND QA2
    AND b.date_met NOT BETWEEN QB1 AND QA2
    AND b.date_met NOT BETWEEN QC1 AND QC2
    AND b.date_met BETWEEN QD1 AND QD2
    AND b.emp_id = P12_ID
    AND a.emp_id = P12_ID;
    Where QA1, QA2, QB1, QB2, QC1, QC2, QD1, QD2 are variable values of pre-defined dates and P12_ID is the ID variable.
    The problem occurs because I need to use the two tables - how can I solve this?
    Thanks,
    Si

    The employee table has multiple actions (action table)
    We want to set certain values i.e the '0000' to certain employees that have had actions on certain dates (the defined variables)
    So it needs to check all the actions within the set dates and give only employees within this criteria the value '0000'
    with the following...
    update emplyees
    set met_emplyees = '0000'
    where emp_id = P12_ID;
    that will always set the employee with '0000'. However '0000' should only be set to employees that had actions on certain dates.
    Cheers
    Si

  • Module pool - for updating Z table

    Moderator message: please using a more meaningful subject.  I've edited it for you this time.
    Hi i have a reuire ment like  this.
    i want to update Z table, by using report program.report is having selection screen ti select data from Z table and to disply in a screen like SM30, i am displying in table control using screen.and i am updating Z table.
    i want to display the selection screen data which ever i have given just above the table control which ever i am displaying now.
    can any body help me out pls.
    Regards
    naidu

    Hi palani thanks for reply.
    i tried in this way already but the problem is we dont know how many values user  will enter to define, suppose if user may enter 1000 entries in one selection field  or beyond that also.
    in this case again the problem.
    and one more thing suppose i ahve selection screen like this
    company code   parameter               mandatory
    sales org.          ranges
    division              ranges
    KUNNR               ranges
    if suppose user entered only mandatory value, and KUNNR we need to display only those two in output, but here in module pool by using screen table if we disable the screen two blank lines will come.
    ex
    cmpany code 0001
    KUNNR         from 1000 TO 2000.
    expected result for this is
    cmpany code 0001
    KUNNR         from 1000 TO 2000.
    i used scren-input for this but ididnt get,
    could you please help me in this.
    thanks and regards
    naidu

  • How can i dynamically update a table in my program?

    Hi there!
    I would like to know if anyone can assist me with advice on how to dynamically update
    a table within my program, with new values from the database?
    Thanking You all.

    Add rows to its model.
    Kind regards,
    Levi

  • How to call a idoc in abap program and updates catsdb table

    how to call a idoc in abap program and updates catsdb table
    thank you,
    Jagrut BharatKumar Shukla

    Hi Kishan,
    You can refer to following help document,
    http://help.sap.com/saphelp_nw04/helpdata/en/bf/d005244e9d1d4d92b2fe7935556b4c/content.htm
    Regards,
    Meera

  • Update of a table via a form

    I created a form with two blocks.
    one of them is a select block for the user
    (not based on a database table) and the other
    one contains the result (through given parameters
    from the first block[the user's query]).
    after the execution of the query and based on the
    data (id) that I got in the second block I would like
    to update another table (database table not shown in the form)
    I created a trigger that calls a procedure. it shows that the
    procedure is executing(using outputs) but there is no update
    in the target table. by the way when trying to close the form(runtime)
    it asks if I would like to save the changes when pressing yes there is an
    error message :"FRM-40508:ORACLE-error-cannot insert record(INSERT)".
    when using the button (trigger) and calling the procedure I get the same
    error message when I have a commit in the procedure. in PL/SQL when calling
    a procedure via a trigger there is no need for a commit. is it the case also
    in a form trigger? and if so why doesn't it update the table? ps.the same procedure
    when executed in sql works good.
    i tried it also with (execute_query) as suggested but it does not work.
    please respond.
    thanks in advance.

    Do you have any other triggers in the form like on-insert/on-update/on-delete???
    If any of these are present then it overrides the operation you are trying to perform..

  • Program RFBELJ10_NACC and update in table TRVOR

    Hi experts,
    I want to run program RFBELJ10_NACC (Document Journal for Italy).
    The user has already run it without test run.
    As a result, the counters have already been updated in table TRVOR.
    How can I re-set them?
    What consequence will it have if I reset them?
    Thank you for your advice.
    Kind regards,
    Linda

    Hi
    I had the same problem in Italy, and it's possible to reset counter, running again report (not in test) from the first period of FY (Fiscal Year) needed to reset.
    In this way you can have a new counter as well and you can verify the updating by SE16 table TRVOR for each month run.
    Antonio

  • How to find program/TCODE which has updated the tables

    Hi All,
    Is there any way to find out program or transcation which has updated the tables.
    BR
    Kamal

    you can see in the table CDHDR or CDPOS which will give you the transaction code and program names.
    Regards,
    Krishna

  • Updating a table used in a calling program

    I am creating an internal version of the notification report program and would like to use a table created in the called program in the main program.
    I generate the data in the called program and would like to "pass" the data into a holding table in the calling program.
    For instance called program loads table i_hold_text, I would like to pass this to calling program ZRIPRSN00 table GT_HOLD_TEXT to use in the SAPScript. Ideas?

    You could use field-symbols.
    like
    DATA: l_text(18) VALUE '(SOURCE_PROGRAM_NAME)table_name[]'.
    field-symbols <fs> type table.
    Assign (ltext) to <fs>.
    if sy-subrc eq 0.
    "Do what you want with <fs>
    endif.

  • How to *Update T710S* table from Program or any FM or BAPI or Any BDC

    Hi,
    I want to update T710S table, Is there any FM or BAPI or Is it possible through BDC, If any body did that, Please Reply me ASAP.
    Regards
    Jan

    Hi Guillaume
    The First FM have update the some Fields only not all fields, So i hope it will not work.
    Second FM retrieve the Data, Not for updating.
    in my guess Need to write Z report or FM.
    if any body have written previously, Please reply me, it would be appreciated.
    Regards
    Jana

Maybe you are looking for

  • Two new apple tv's in the home network...

    Hi, Recently i bought both my kids an apple tv. I am worried now that my home network will get jammed or get really slow as the both watch films from the shared iTunes library on my iMac. The actual media files are on an external hard disk, witch is

  • Business Graphics: Link between SeriesList and Categories

    Hello everyone, I have a Business Graphics with a Category Subelement and a SeriesList with a Value inserted. The Series List is linked to a node, so my series are dinamically created during runtime. My problem is that the number of categories i have

  • Oddball Video Format Too Small

    My daughter's barn has a Lorex security DVR. It saves the video in some odd format (h.264?), but they do provide a tool for converting it to AVI. So I've done that. The first screenshot is the G-Spot for the resulting AVI file. It looks a little odd,

  • Anybody know what flash player works with mac 10.5.8  Intel

    Having trouble finding flash player that works with mac 10.5.8 intel

  • Macbook pro retina display has pinkish tint?

    I have bought a  macbook pro 15.4" with retina display.Everything is good but the screen.When I had a white wallpaper , then I saw the pinkish tint on the left and the normal white on the right, specially in the evening or in low light.How can I fix