I want to update data

I'm a beginner in programming in Java. I can display data from mySQL database in a JTabe.But I want to modify/ update table data. I could not update my database table using the sun's JDBCAdapter. is there any better way ?
Thank you for your help.

Dear Friend,
In fact, i have created a database in mysql. After that i displayed the database in Jtable using the JDBC. But i can't updating the table data from JDBC. I have used the sun's JDBCAdapter.java code with my program. After running the programme, when i modify the table a message comes that-" Not sending update to database ". I am attached the code.Can you suggest me where i will put the update statement for database table update. ?
pitab/**
* @(#)JDBCAdapter.java     1.6 98/02/10
* Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
* This software is the confidential and proprietary information of Sun
* Microsystems, Inc. ("Confidential Information"). You shall not
* disclose such Confidential Information and shall use it only in
* accordance with the terms of the license agreement you entered into
* with Sun.
* SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
* SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
* IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
* SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
* THIS SOFTWARE OR ITS DERIVATIVES.
* An adaptor, transforming the JDBC interface to the TableModel interface.
* @version 1.20 09/25/97
* @author Philip Milne
import java.util.Vector;
import java.sql.*;
import javax.swing.table.AbstractTableModel;
import javax.swing.event.TableModelEvent;
public class JDBCAdapter extends AbstractTableModel {
Connection connection;
Statement statement;
ResultSet resultSet;
String[] columnNames = {};
Class[] columnTpyes = {};
Vector          rows = new Vector();
ResultSetMetaData metaData;
public JDBCAdapter(String url, String driverName,
String user, String passwd) {
try {
Class.forName(driverName);
System.out.println("Opening db connection");
connection = DriverManager.getConnection(url, user, passwd);
statement = connection.createStatement();
catch (ClassNotFoundException ex) {
System.err.println("Cannot find the database driver classes.");
System.err.println(ex);
catch (SQLException ex) {
System.err.println("Cannot connect to this database.");
System.err.println(ex);
public void executeQuery(String query) {
if (connection == null || statement == null) {
System.err.println("There is no database to execute the query.");
return;
try {
resultSet = statement.executeQuery(query);
metaData = resultSet.getMetaData();
int numberOfColumns = metaData.getColumnCount();
columnNames = new String[numberOfColumns];
// Get the column names and cache them.
// Then we can close the connection.
for(int column = 0; column < numberOfColumns; column++) {
columnNames[column] = metaData.getColumnLabel(column+1);
// Get all rows.
rows = new Vector();
while (resultSet.next()) {
Vector newRow = new Vector();
for (int i = 1; i <= getColumnCount(); i++) {
     newRow.addElement(resultSet.getObject(i));
rows.addElement(newRow);
// close(); Need to copy the metaData, bug in jdbc:odbc driver.
fireTableChanged(null); // Tell the listeners a new table has arrived.
catch (SQLException ex) {
System.err.println(ex);
public void close() throws SQLException {
System.out.println("Closing db connection");
resultSet.close();
statement.close();
connection.close();
protected void finalize() throws Throwable {
close();
super.finalize();
// Implementation of the TableModel Interface
// MetaData
public String getColumnName(int column) {
if (columnNames[column] != null) {
return columnNames[column];
} else {
return "";
public Class getColumnClass(int column) {
int type;
try {
type = metaData.getColumnType(column+1);
catch (SQLException e) {
return super.getColumnClass(column);
switch(type) {
case Types.CHAR:
case Types.VARCHAR:
case Types.LONGVARCHAR:
return String.class;
case Types.BIT:
return Boolean.class;
case Types.TINYINT:
case Types.SMALLINT:
case Types.INTEGER:
return Integer.class;
case Types.BIGINT:
return Long.class;
case Types.FLOAT:
case Types.DOUBLE:
return Double.class;
case Types.DATE:
return java.sql.Date.class;
default:
return Object.class;
public boolean isCellEditable(int row, int column) {
try {
return metaData.isWritable(column+1);
catch (SQLException e) {
return false;
public int getColumnCount() {
return columnNames.length;
// Data methods
public int getRowCount() {
return rows.size();
public Object getValueAt(int aRow, int aColumn) {
Vector row = (Vector)rows.elementAt(aRow);
return row.elementAt(aColumn);
public String dbRepresentation(int column, Object value) {
int type;
if (value == null) {
return "null";
try {
type = metaData.getColumnType(column+1);
catch (SQLException e) {
return value.toString();
switch(type) {
case Types.INTEGER:
case Types.DOUBLE:
case Types.FLOAT:
return value.toString();
case Types.BIT:
return ((Boolean)value).booleanValue() ? "1" : "0";
case Types.DATE:
return value.toString(); // This will need some conversion.
default:
return "\""+value.toString()+"\"";
public void setValueAt(Object value, int row, int column) {
try {
String tableName = metaData.getTableName(column+1);
// Some of the drivers seem buggy, tableName should not be null.
if (tableName == null) {
System.out.println("Table name returned null.");
String columnName = getColumnName(column);
String query =
"update "+tableName+
" set "+columnName+" = "+dbRepresentation(column, value)+
" where ";
// We don't have a model of the schema so we don't know the
// primary keys or which columns to lock on. To demonstrate
// that editing is possible, we'll just lock on everything.
for(int col = 0; col<getColumnCount(); col++) {
String colName = getColumnName(col);
if (colName.equals("")) {
continue;
if (col != 0) {
query = query + " and ";
query = query + colName +" = "+
dbRepresentation(col, getValueAt(row, col));
System.out.println(query);
System.out.println("Not sending update to database");
// statement.executeQuery(query);
catch (SQLException e) {
// e.printStackTrace();
System.err.println("Update failed");
Vector dataRow = (Vector)rows.elementAt(row);
dataRow.setElementAt(value, column);
}

Similar Messages

  • Want to update data in a view based on multiple tables

    Hi
    I am facing a problem i want to update data in tables using a view. As that view is based on multiple tables so i am unable to update data. i came to know we can update table from view only if view is based on single table. so if anyone knows any alternative please let me know.
    Thanx
    Devinder

    Devinder,
    The table can be updated through a view based on multiple tables, if and only if the table is a "key preserved" table. Rather than explaining myself, i avoided the burden of typing by finding the material in Oracle Docs and pasting it for you :-)
    If you want a join view to be updatable, all of the following conditions must be
    true:
    1. The DML statement must affect only one table underlying the join.
    2. For an INSERT statement, the view must not be created WITH CHECK
    OPTION, and all columns into which values are inserted must come from a
    key-preserved table. A key-preserved table in one for which every primary
    key or unique key value in the base table is also unique in the join view.
    3. For an UPDATE statement, all columns updated must be extracted from a
    key-preserved table. If the view was created WITH CHECK OPTION, join
    columns and columns taken from tables that are referenced more than once
    in the view must be shielded from UPDATE.
    4. For a DELETE statement, the join can have one and only one key-preserved
    table. That table can appear more than once in the join, unless the view was
    created WITH CHECK OPTION.
    HTH
    Naveen

  • I want to update date field in oracle table using database adaptor

    Hi Guys,
    I want to update date in oracle table field which is 'DATE' type , but i am getting following error.
    Pure SQL Exception.
    Pure SQL Execute of update crp3apps.IFACE_SO_DATE_CHANGES set PROCESSED_DATE=? where CTRL_ID=? failed. Caused by java.sql.SQLException: ORA-01830: date format picture ends before converting entire input string
    The Pure SQL option is for border use cases only and provides simple yet minimal functionality. Possibly try the "Perform an operation on a table" option instead.
    </summary>
    </part>
    - <part name="detail">
    <detail>
    ORA-01830: date format picture ends before converting entire input string
    </detail>
    i am formated the date using following code and assigned to one variable.
    ora:formatDate(ora:getCurrentDateTime(),'dd-MMM-yyyy hh:mm:ss ')
    this is update query
    update crp3apps.IFACE_SO_DATE_CHANGES set PROCESSED_DATE=#date where CTRL_ID=#id
    Please provide solution.
    regards
    janardhan

    The thing is that XSLT often doesn't deliver the functionality required when it comes to times.
    You suggest appening "Z" to the time but this means that the time is now in UTC time. What if the system from where the date is being converted is running in NZ using local time? Other systems that recieve the date (and correctly handle the time zone) will now have a time that is out by a number of hours.
    You often can't ignore the time zone (drop the 'Z') as if you send the time to a system it has to either assume the time is local to it (which may not be the case... the other system coudl be in a different time zone) or assume the time is UTC (I think crossfire does this by default).
    Typically can't just append a time zone (e.g. +11:00) either as many places have daylight savings so the value to appended is variable (you then need some way of determining what the value is... either Java Embedding or a Service).
    As you mention it does depend on the use case but in many circumstances using Jaba Embedding, not as suggested above but with the appropriate Java.util.Calendar classes, is the best way to handle date and time in BPEL. Even still you need to ascertain the format of times external to the system and ensure you parse them correctly.
    ANd even if you do all this you can still run into problems. I've seen a real world example where two systems which both handled time zones correctly and had previously been working together for quite a while, satrted reporting different times. It turns out that only one of them had had the most recent Java Time Zone patches applied and there had been a change in the dates for daylight savings here (Australia). Be warned!

  • Update data in r/3 from webdynpro using bapi

    Hi ,
    i am new to webdynpro.
    i want to update data say sales order in r/3 backend from webdynpro.
    can i have some links for the same.
    i have seen previous forums in following link, but couldn't open.do i need to register to have some extra rights.
    /thread/12846 [original link is broken]
    thanks in advance

    Hi Satya
    In order to update data in R/3 from web dynpro you need to use RFC or BAPI
    The Adaptive Remote Function Call (Adaptive RFC) is a technology that enables the Web Dynpro application developer to use the business functions encapsulated in Business APIs (BAPIs) even after a structure modification, without having to provide the new data using a second back end or a new structure with subsequent regeneration of the proxies.
    Procedure for Importing Adaptive RFC model is as follows
      1. Choose the context menu entry Create Model on the Models node of the relevant Web Dynpro component.
    2. In the model wizard, choose Import Adaptive RFC Model followed by Next.
    3. Make the required entries – for example, to specify where the generated RFC model instances and RFC metadata are to be stored.
    4. In the next wizard window, you enter your user data for the SAP System that contains the BAPIs from which you want to generate the proxies. You use it to log on to the SAP System online.
    To be able to log on to the SAP System, it must be entered in the logon group.
    5.  Next select the BAPIs for which you want to create Java proxies in a generation process. Then choose Next to proceed to the next wizard window.
    6.The import log provides information about the generated model classes, properties, and model relations. Choose Finish to start the generation process.
    Now add this model in "Used Model" for your application
    Now for graphic display you create view,for the progarm control create controller and used this model to retrieve & update data.
    For more information about web dynpro for Java refer
    http://help.sap.com/saphelp_nw2004s/helpdata/en/14/c897427f18d06ae10000000a155106/frameset.htm
    For information about RFC & BAPI
    http://help.sap.com/saphelp_nw2004s/helpdata/en/22/042860488911d189490000e829fbbd/frameset.htm
    Regards
    Gauri

  • Updating data from PSA to Data Target

    Hi,
    I just want to update data from PSA to data target.
    There is a process chain running daily it will updating Master Data in to 0Vendor object. This process chain is updating only upto PSA not the data target. I just want to update from PSA to data target.
    There is a update rule for 0Vendor but itu2019s not active at the movement and also it is not properly mapped with the 0Vendor.
    Is there any other method which I can update data from PSA to Data target with in the same process chain.
    Thanks
    Ganesh

    If this is BW 3.5, change the infopackage setting to load to data target as well.
    This is a other w ay than using the update from infopackage.
    if this is 7.0, Use the DTP to load from PSA(datasource) to Target.
    Let me know if this helps.
    Thanks
    Sachin

  • Updating data in APO demand planning key figure

    Hi
    We have a key figure in Demand planning which is not present in Info cube, This key figure is just avaialable in SAPAPO  SDP94for manullay key in some data, Now I want to update data in this key figure via extrnal file i.e text file.
    Could u suggest some ways for this, Remember this key figure is not present in Info cube, Hence we can not feed in External file to Info cube, We some other way for updating data in this key figure,
    Thanks and regards,
    Nitin Lavhe

    If your client is not Ok with standard way of flat file upload, Also If you will get a file from external customer on weekly basis then definitely they will put it somewhere either on local server or application server.
    I would suggest, Define the format for the flat file,Ask User to put that file on application server, Write a simple program to get data from that file on application server, Update the KeyFigure using standard BAPIs available,After updation delete that file from server.Schedule this program in background on weekly basis so that every time it will check for new file on server path and update the Keyfigure accordingly.
    I know this is a custom development but this will work.
    Thanks,
    Saurabh

  • Best way to edit/update data in JSP ?

    Hi Friends,
    I want to know about Update / Edit data procedure in JSP.
    ie.
    If we have one form having 10 fields, and we need to change only
    1 field then do we require to set update query for all 10 fields ?
    don't it make some overload ?
    Can you give me solution like that ?
    and I want to update data like we use CakePHP scaffold functionality.
    data from database is displayed in field and we just need to edit data
    and save it.
    Can we have such in JSP ? see I don't know struts or any frameworks
    Better you will suggest way to do in JSP.
    for Insert I use Bean [ one java class get the parameters for all fields and query ]
    Please suggest me to set the value to field on edit / update
    and best way to update the data.
    -GkR

    It's easy if you want upade game files, not game engine binary.
    You can make your app that will load swf file. So you can make engine that will load all files externaly from device. Firstly you run app and if it connected by wifi - ask user for upadate wish and that simply download from http files as binary and save they using FileSystem

  • Update date daily automatically

    If I wanted to have Dreamweaver update each day's date automatically how would I do that? For example, "updated xx/xx/xxxx."

    You could do this with a script. Place the following script where you want the updated date to apprear. This will not work if the person has javascript turned off in their browser.
    Jim
    <script type="text/javascript">
    datUpdated = new Date(document.lastModified) ;
    datMonth = datUpdated.getMonth() + 1 ;
    datDate = datUpdated.getDate() ;
    datYear = datUpdated.getYear() ;
    document.write("<em>Last Updated: " + datMonth + "/" + datDate + "/" + datYear + "</em>") ;
    </script>

  • Update data with subquery

    Hi all,
    I have two tables A(a1,a2,a3) and B(b1,b2,b3) then I want to update data
    in column A.a3 to '4' where A.a1 = B.b1 and A.a2 = B.b2
    How to write this update script?
    Thank you,
    Mcka

    Hi Rodwest,
    Thank you for your answer ,but can I use this script
    update A
    set A.a3 = 4
    where (a1,a2) IN (select b1,b2
    from B
    where A.a1 = B.b1 and A.a2 = B.b2)
    If can use, which one is better?
    Thank you ,
    Vilas

  • Can I update datas of Power Query after making relation tables in Power Pivot ?

    Can I update datas of Power Query after making relation tables in Power Pivot ?
    I want to update datas at day by day to viewing today's graph by Power View on Excel.
    Power Query use to transform web site to Power Pivot data model table.
    Power Pivot use to making relasing tables, and making measuers.
    Regards,
    Yoshihiro Kawabata.

    Hi Yoshihiro,
    Can you share an example of the things you are doing in Power Pivot? There are some operations that prevent the query from being refreshed in Power Query; this is not ideal so we are currently working on fixing it.
    Thanks for your feedback.

  • I want to update my IPODtouch, but it will erase all my data. How do I sync my ipod to a new computer so itunes will not erase my data???

    I want to update my IPODtouch, but it will erase all my data. How do I sync my ipod to a new computer so itunes will not erase my data???

    Follow these instructions. When you restore the iPod from backup as the article says your iPod will also be updated.
    Syncing to a "New" Computer or replacing a "crashed" Hard Drive: Apple Support Communities

  • 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 .

  • We want to update our second iPhone 4 on one single iMac, but are afraid that the data of the 1st phone will be overwritten when syncing.

    We want to update our second iPhone 4 on one single iMac, but are afraid that the data of the 1st phone will be overwritten when syncing the 2nd phone. What to do?

    Create a separate user account for the second phone. See http://support.apple.com/kb/HT1495 (and http://support.apple.com/kb/HT2542).

  • I want to update the OS of the Macbook Pro I bought today to Lion, but at "purchase date" I can only choose 2011. Now what?

    I want to update the OS of the Macbook Pro I bought today to Lion, but at "purchase date" I can only choose 2011. Now what?

    Sorry but I don't completely understand your question or what you are trying to do.
    If you purchase a new MBP Today, Jan 3 2012, it should already have OS X Lion 10.7.x installed on it.
    Only some left over early 2011 model that stores may have had sitting around would of come with Snow Leopard 10.6.8. Or even if you bought a Reburbished model from Apple it would of still came from them with Lion.
    So my questions are.
    1) Did you buy this new from a authorized Apple store or reseller?
    2) If not new was it purchased from an authorized Apple store or reseller?
    3) To my knowledge when trying to do updates to the OS there is no check of purchase date. So what exactly are you doing that asks for a purchase date?
    If new then just use the Software Updates in the Apple Logo menu item.
    If not new and it originally came with Snow Leopard or Leopard you will have to buy OS X Lion at the Online Apple Store. If that is the case then nyou need to put in the original date the unit was purchased NEW and or manufactured. That way the Online Apple Store can tell if Lion will function on that model properly.

  • Want some Userexit or Badi for me23n for updating dates .

    Hi ,
    i want to update the validity start and validity end before displaying in the aditional info TAB of the ME23N.  
    i need to pass the pricing date(PRSDT) from VFKP table to these fields...
    Can anyone help me regarding this .
    Regards,
    Shilpa.

    Hi,
    You can achieve this using enhancement MM06E005 i am not sure if you have these fields on the header or the item level, i assume they are on the header level so you can use FM EXIT_SAPMM06E_006.
    Regards,
    Himanshu

Maybe you are looking for

  • Hard Drive Corrupted - No Disc or Optical Drive Available.

    HI all, Just looking for some advice. I have a MacBook Pro (15-inch) Early 2011. I think it was Snow Leopard installed. Yesterday, the hard drive came to the end of it's life. During use the computer started to make a buzzing sound every two seconds

  • Payment run F110 / RFFOAVIS_FPAYM: Print vs. Email

    Hi everybody, I have a question regarding the printing of payment advices within the payment run F110 via program RFFOAVIS_FPAYM. Whenever there is a email address maintained in the customer master data the payment advice is sent as an email instead

  • Change the FIND display from LAST OPENED to LAST MODIFIED.

    When I search for a folder/file, I want to sort by date and view when the folder/file was LAST MODIFIED. I find LAST OPENED to be useless. Someone in the Dept. may have opened a file just to see what it was, but so what. That tells me nothing about t

  • Custom Printing of data forms

    We need custom printing for Hyperion planning forms. We are using Oracle® Hyperion Planning, Fusion Edition - 11.1.2.2.. Can anyone guide?

  • Color field name

    Hi all, Missing how to make the field name color.... Regards Edited by: User_Apex on Jul 9, 2010 3:23 AM