Update database from Jtable

Hi all,
I am trying to update database from Jtable. I added Jtable to scrollpane .
My question is..
after updating the Jtable..I want to save the details to database..when I click save button on my screen...how to do that? Please help me out! Thanks in advance..
Here is the code that I wrote...
public class VasuTest extends JFrame {
private boolean DEBUG = true;
Vector column_list = new Vector();
Vector rows = new Vector();
public VasuTest() {
super("VasuTest");
     JToolBar toolBar = new JToolBar();
JButton button = null;
button = new JButton("Send Email");
button.setToolTipText("This is the Exit button");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
     System.out.println("Send Email");
toolBar.add(button);
button = new JButton("Save");
button.setToolTipText("This is the Save button");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
     System.out.println("Save");
toolBar.add(button);
button = new JButton("Exit");
button.setToolTipText("This is the Exit button");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
     System.exit(0);
toolBar.add(button);
     JPanel ContentPane = new JPanel();
ImageIcon i1 = new ImageIcon("Dongle.gif");
JLabel j1 = new JLabel( i1, JLabel.CENTER);
     ContentPane.add(j1,BorderLayout.CENTER);
     setContentPane(ContentPane);
     JDBCT myModel = new JDBCT();
String q = "select a.email_no,a.email_ln_no,b.cust_no,null customer_name,null cdate,a.batch_no,b.purch_ord_no,a.user_part_no,null part_desc,a.user_upgraded_part_no,null prod_id,a.qty,a.price,a.encrypted_sum_id,a.decrypted_sum_id,a.approval_key,a.status_cd,decode(a.status_cd,'APPROVED','true','ERROR','false','PROCESSED','true') approved,null end_cust,null sales_ord,null so_line,null sales_ord_cust,null shipment ,null sales_end_cust_name ,null shipment_line,a.note,null fromcust from upgrade_req_key_s3 a,upgrade_req_s3 b where a.email_no = b.email_no order by a.email_no,a.email_ln_no";
myModel.setQuery();
final Font f = new Font("SansSerif", Font.BOLD, 10);
JTable table = new JTable(myModel);
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
// Container ContentPane = getContentPane();
     int v = ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS;
     int h = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS;
     JScrollPane scrollPane = new JScrollPane(table,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
     scrollPane.setPreferredSize ( new Dimension ( 770, 400 ) );
ContentPane.add(toolBar,BorderLayout.CENTER);
//Add the scroll pane to this window.
ContentPane.add(scrollPane,BorderLayout.CENTER);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
public class JDBCT extends AbstractTableModel {
Vector cache; // will hold String[] objects...
int colCount;
int rowHeight;
String [] headers;
Connection db;
Connection conn;
Statement statement;
String currentURL;
// public QueryTableModel() {
// cache = new Vector();
// new oracle.jdbc.driver.OracleDriver();
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
catch (ClassNotFoundException e) {
System.out.println(e.getMessage());
System.exit(-1);
String url = "jdbc:odbc:c3-erp,s3,s3";
public String getColumnName(int i) {
     if (i == 0)      {  return      "Email No"                     ;     } else
if (i == 1)      {  return      "Email Line No.";} else
     if (i == 2)      {  return      "Customer";} else
     if (i == 3)      {  return      "Customer Name";} else
     if (i == 4)      {  return      "Date";} else
     if (i == 5)      {  return      "Batch No";} else
     if (i == 6)      {  return      "Customer PO";} else
     if (i == 7)      {  return      "Upgrade From Part";} else
     if (i == 8)      {  return      "Part Description";} else
     if (i == 9)      {  return      "Upgrade To Part";} else
     if (i == 10)      {  return      "Product Id";} else
     if (i == 11)      {  return      "Quantity";} else
     if (i == 12)      {  return      "Price";} else
     if (i == 13)      {  return      "Encypted Sum ID";} else
     if (i == 14)      {  return      "Decrypted Serial No";} else
     if (i == 15)      {  return      "Key";} else
     if (i == 16)      {  return      "Status";} else
     if (i == 17)      {  return      "Approved";} else
     if (i == 18)      {  return      "End Customer";} else
     if (i == 19)      {  return      "Sales Order";} else
     if (i == 20)      {  return      "SO Line";} else
     if (i == 21)      {  return      "Sales Order End Customer";} else
     if (i == 22)      {  return      "Sales Order End Customer Name";} else
     if (i == 23)      {  return      "Shipment";} else
     if (i == 24)      {  return      "Shipment Line";} else
     if (i == 25)      {  return      "Errors";} else
     if (i == 26)      { return       "From"; }
     else {return headers[i-1] ;}
public int getColumnCount() { return colCount; }
public int getRowCount() { return cache.size(); }
//public Class getColumnClass(int c) {
// return getValueAt(0, c).getClass();
// overloaded isCellEditable method so that it returns true
// in reference to a cell being editable.
public boolean isCellEditable(int row, int col) { return true; }
// overloaded setValyeAt which updates the data Vector and
// calls the fireTableRowsUpdated() to notify any listeners
// that data has changed and they need to redraw.
public void setValueAt(Object value, int row, int col) {
((String[])cache.elementAt(row))[col] = (String)value;     
     fireTableRowsUpdated(row,row);     
public void getInfo () {
System.out.println("Row Count is : " + cache.size());
     System.out.println("Value at 0,0 is : " + getValueAt(0,0));
//     boolean res = isCellEditable(0,0);
//     System.out.println("The value of the Boolean result is : " + res);
public Object getValueAt(int row, int col) {
return ((String[])cache.elementAt(row))[col];
// All the real work happens here!
// In a real application, we'd probably perform the query in a separate thread.
public void setQuery() {
cache = new Vector();
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn = DriverManager.getConnection ("jdbc:odbc:c3-erp","s3","s3");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select a.email_no,a.email_ln_no,b.cust_no,null customer_name,null cdate,a.batch_no,b.purch_ord_no,a.user_part_no,null part_desc,a.user_upgraded_part_no,null prod_id,a.qty,a.price,a.encrypted_sum_id,a.decrypted_sum_id,a.approval_key,a.status_cd,decode(a.status_cd,'APPROVED','true','ERROR','false','PROCESSED','true') approved,null end_cust,null sales_ord,null so_line,null sales_ord_cust,null shipment ,null sales_end_cust_name ,null shipment_line,a.note,null fromcust from upgrade_req_key_s3 a,upgrade_req_s3 b where a.email_no = b.email_no order by a.email_no,a.email_ln_no");
ResultSetMetaData meta = rs.getMetaData();
colCount = meta.getColumnCount();
String[] record = new String[27];      
// Now we must rebuild the headers array with the new column name
headers = new String[27];
for (int h=0; h < 27; h++) {
// headers[h-1] = meta.getColumnName(h);
     headers[h] = getColumnName(h);
// and file the cache with the record from our query. This would
// be practical if we were expecting a few million records to our
// response query, but we are not so we can do this.
while(rs.next()) {
     for (int i=0; i < colCount; i++) {
     record[i] = rs.getString(i + 1);
     cache.addElement(record);
     // Get the FIRST column of the table tableView
// TableColumn column0 = table.getColumn(cache.elementAt(0));
// Set the cell editor as non editable.
// column0.setCellEditor(new EditableCellEditor(new JComboBox(), true));
fireTableChanged(null); // notify everyone the we had a new table.
catch (Exception e) {
cache = new Vector(); // blank it out and keep going.
     e.printStackTrace();
public static void main(String[] args) {
VasuTest frame = new VasuTest();
frame.pack();
frame.setVisible(true);
}

When you click on the save button, you need to go through the model and retrieve the values getValueAt().
Convert to whatever type you want since getValueAt() returns type Object and update the DB.

Similar Messages

  • Update database from 11.2.0.1 to 11.2.0.3

    Hi all,
    I have installed 11gR2 *(11.2.0.1)* on Redhat Linux 5.4.
    No I want to update database version to *11.2.0.3*
    How to achieve this.
    This is for testing purpose.
    Bala:)

    You do this by reading the readme which comes with every patch set.
    No one here would abstract it for you.
    Sybrand Bakker
    Senior Oracle DBA

  • How to edit databases from JTable?

    Hello everyone, I would like to ask your help on how we can edit JTable cells that would be reflected into the database, or how do we change the database via a JTable.
    I have the installer of an application which I made with Java SE called FuelStation.exe
    My class files are ready for sharing along with its source files.
    I have placed it in this location in my website:
    http://www.apachevista.com/alphaprojects/runfiles/
    It is complete with full details about databases, proposed mysql embed, and so on. Please see the file and notify me at [email protected]
    Here is my sample code:
    // DisplayQueryResults.java
    // Display the contents of the Authors table in the
    // Books database.
    import java.awt.BorderLayout;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import java.sql.SQLException;
    import javax.swing.JFrame;
    import javax.swing.JTextArea;
    import javax.swing.JScrollPane;
    import javax.swing.ScrollPaneConstants;
    import javax.swing.JTable;
    import javax.swing.JOptionPane;
    import javax.swing.JButton;
    import javax.swing.Box;
    import javax.swing.JInternalFrame;
    import java.util.*; // for the Bundle
    import javax.swing.event.InternalFrameEvent;
    import javax.swing.event.InternalFrameListener;
    import javax.swing.event.InternalFrameAdapter;
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
    import javax.swing.ListSelectionModel;
    import javax.swing.event.ListSelectionEvent;
    import javax.swing.event.ListSelectionListener;
    import javax.swing.event.*; // step 1
    import javax.swing.table.TableModel; // step 1
    public class DisplayQueryResults extends JInternalFrame implements TableModelListener { // step 2
    // JDBC driver, database URL, username and password
    ResourceBundle bundle = ResourceBundle.getBundle("Accounting");
    final String JDBC_DRIVER = bundle.getString("Driver");
    final String DATABASE_URL = bundle.getString("URL");
    final String USERNAME = bundle.getString("User");
    final String PASSWORD = bundle.getString("Password");
    // default query retrieves all data from authors table
    //static final String DEFAULT_QUERY = "SELECT authors.lastName, authors.firstName, titles.title, titles.editionNumber FROM titles INNER JOIN (authorISBN INNER JOIN authors ON authorISBN.authorID=authors.authorID) ON titles.isbn=authorISBN.isbn";
    final String DEFAULT_QUERY = bundle.getString("Query");
    private ResultSetTableModel tableModel;
    private JTextArea queryArea;
    static final int xOffset = 0, yOffset = 200;
    private boolean ALLOW_COLUMN_SELECTION = false;
    private boolean ALLOW_ROW_SELECTION = true;
    // create ResultSetTableModel and GUI
    public DisplayQueryResults() {  
    super("Sales of the Day",
    true, //resizable
    true, //closable
    true, //maximizable
    false);//iconifiable
    //...Create the GUI and put it in the window...
    //Set the window's location.
    setLocation(xOffset, yOffset);
    // create ResultSetTableModel and display database table
    try {
    // create TableModel for results of query SELECT * FROM authors
    tableModel = new ResultSetTableModel(JDBC_DRIVER, DATABASE_URL,
    USERNAME, PASSWORD, DEFAULT_QUERY);
    // set up JTextArea in which user types queries
    queryArea = new JTextArea(DEFAULT_QUERY, 1, 100);
    queryArea.setWrapStyleWord(true);
    queryArea.setLineWrap(true);
    JScrollPane scrollPane = new JScrollPane(queryArea,
    ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
    ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    // set up JButton for submitting queries
    JButton submitButton = new JButton("Submit Query");
    // create Box to manage placement of queryArea and
    // submitButton in GUI
    Box box = Box.createHorizontalBox();
    box.add(scrollPane);
    box.add(submitButton);
    // create JTable delegate for tableModel
    JTable resultTable = new JTable(tableModel);
    resultTable.setFillsViewportHeight(true); // Makes the empty space heights white
    resultTable.setRowSelectionAllowed(true);
    resultTable.getModel().addTableModelListener(this); // step 3
    // place GUI components on content pane
    add(box, BorderLayout.NORTH);
    add(new JScrollPane(resultTable), BorderLayout.CENTER);
    // create event listener for submitButton
    submitButton.addActionListener(
    new ActionListener()
    // pass query to table model
    public void actionPerformed(ActionEvent event)
    // perform a new query
    try
    tableModel.setQuery(queryArea.getText());
    } // end try
    catch ( SQLException sqlException)
    JOptionPane.showMessageDialog(null,
    sqlException.getMessage(), "Database error",
    JOptionPane.ERROR_MESSAGE);
    // try to recover from invalid user query
    // by executing default query
    try {
    tableModel.setQuery(DEFAULT_QUERY);
    queryArea.setText(DEFAULT_QUERY);
    } // end try
    catch (SQLException sqlException2) {
    JOptionPane.showMessageDialog(null,
    sqlException2.getMessage(), "Database error",
    JOptionPane.ERROR_MESSAGE);
    // ensure database connection is closed
    tableModel.disconnectFromDatabase();
    System.exit(1); // terminate application
    } // end inner catch
    } // end outer catch
    } // end actionPerformed
    } // end ActionListener inner class
    ); // end call to addActionListener
    //...Then set the window size or call pack...
         setSize(750,300);
    setVisible(true); // display window
    } // end try
    catch (ClassNotFoundException classNotFound) {
    JOptionPane.showMessageDialog(null,
    "MySQL driver not found", "Driver not found",
    JOptionPane.ERROR_MESSAGE);
    System.exit(1); // terminate application
    } // end catch
    catch (SQLException sqlException) {
    JOptionPane.showMessageDialog(null, sqlException.getMessage(),
    "Database error", JOptionPane.ERROR_MESSAGE);
    // ensure database connection is closed
    tableModel.disconnectFromDatabase();
    System.exit(1); // terminate application
    } // end catch
    // dispose of window when user quits application (this overrides
    // the default of HIDE_ON_CLOSE)
    setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    // ensure database connection is closed when user quits application
    addInternalFrameListener(
    new InternalFrameAdapter() {
    // disconnect from database and exit when window has closed
    public void windowClosed(WindowEvent event) {
    tableModel.disconnectFromDatabase();
    System.exit(0);
    } // end method windowClosed
    } // end WindowAdapter inner class
    ); // end call to addWindowListener
    } // end DisplayQueryResults constructor
    public void tableChanged(TableModelEvent e) { // step 4
    int row = e.getFirstRow();
    int column = e.getColumn();
    TableModel model = (TableModel)e.getSource();
    String columnName = model.getColumnName(column);
    Object tableModel = model.getValueAt(row, column);
    // Do something with the data...
    System.out.println(tableModel);
    System.out.println("data");
    // execute application
    public static void main(String args[]) {
    new DisplayQueryResults();
    } // end main
    } // end class DisplayQueryResults
    My question is in lines 177-187:
    public void tableChanged(TableModelEvent e) { // step 4
    int row = e.getFirstRow();
    int column = e.getColumn();
    TableModel model = (TableModel)e.getSource();
    String columnName = model.getColumnName(column);
    Object tableModel = model.getValueAt(row, column);
    // Do something with the data...
    System.out.println(tableModel);
    System.out.println("data");
    Why is my listener not working or why is it not implemented when I click the cells in the JTable and why is it not reflected into the JTable or into the console?
    If this is Flash, Things can be done easily, but this is Java, and I dont know much about this language. I admit that I am new to this -intirely new.
    PS:
    When you have solved the problem, please notify me with the code that's changed
    and please share it to others if you like so.
    Best Wishes: Oliver Bob Lagumen
    Email: [email protected]
    website: www.apachevista.com
    Oliver Bob Lagumen
    Edited by: Oliverbob on Jan 24, 2008 9:03 PM

    Why is my listener not working or why is it not implemented when I click the cells in the JTable and why is it not reflected into the JTable or into the console?What does happen when you click on the cells?
    Does the ResultSetTableModel report the cells as editable? If not you will never get to edit their contents, and so the table's model won't change, and so the table model listener will never get invoked.
    When you post code here use the code tags. Basically you put {code} at the start of your code and again at the end. That way the code will be readable.
    Try to post minimal examples with which others can reproduce your problem. In this case "minimal" would involve removing or drastically simplifying a lot of the GUI stuff which is just noise. But "reproduce" would involve including the ResultSetTableModel.
    When you have solved the problem, please notify me with the code that's changedAvoid this.
    What you say here is quite possibly not what you mean. But, in any event, while there might be plenty of interest in helping with specific problems there will likely be none in writing your code. Your problem remains yours. But your solution and your code - prompted by whatever help you might recieve - will also be yours.

  • Updating Database From csv File in Web Dynpro Java

    Hi Gurus,
    I'd like to write an WDJ where the (super-)user can upload a csv file and delta-update the content of this file witch an external database.
    Could you please give some me hints & examples.
    Thanks in advance,
    Farid
    ps. answers will be rewarded with points, of cource.

    Hi Farid:
    From your question it seems like you want to write a WDJ application which writes a CSV file after connecting to a database and everytime you do so, updates the file with the new record from the DB.
    For this, I wouldnt think to write an application in WebDynpro since its an over kill, unless you want to host this appln in a portal environment and want it accessible for  a set of people.
    Ideally you could use the JDK api to open a connection to the database and then then file api to write to files. You would need to use an identifier somewhere to know the last record read and written to the file.
    Incase you put in the type of db you want to connect to, i could be of more help
    Thanks,
    LioneL

  • Editing MySQL Database from JTable

    Hello everyone, I would like to ask your help on how we can edit JTable cells that would be reflected into the database, or how do we change the database via a JTable.
    I have the installer of an application which I made with Java SE called FuelStation.exe
    My class files are ready for sharing along with its source files.
    I have placed it in this location in my website:
    http://www.apachevista.com/alphaprojects/runfiles/
    It is complete with full details about databases, proposed mysql embed, and so on. Please see the file and notify me at [email protected]
    Here is my sample code:
    // DisplayQueryResults.java
    // Display the contents of the Authors table in the
    // Books database.
    import java.awt.BorderLayout;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import java.sql.SQLException;
    import javax.swing.JFrame;
    import javax.swing.JTextArea;
    import javax.swing.JScrollPane;
    import javax.swing.ScrollPaneConstants;
    import javax.swing.JTable;
    import javax.swing.JOptionPane;
    import javax.swing.JButton;
    import javax.swing.Box;
    import javax.swing.JInternalFrame;
    import java.util.*; // for the Bundle
    import javax.swing.event.InternalFrameEvent;
    import javax.swing.event.InternalFrameListener;
    import javax.swing.event.InternalFrameAdapter;
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
    import javax.swing.ListSelectionModel;
    import javax.swing.event.ListSelectionEvent;
    import javax.swing.event.ListSelectionListener;
    import javax.swing.event.*; // step 1
    import javax.swing.table.TableModel; // step 1
    public class DisplayQueryResults extends JInternalFrame implements TableModelListener { // step 2
    // JDBC driver, database URL, username and password
    ResourceBundle bundle = ResourceBundle.getBundle("Accounting");
    final String JDBC_DRIVER = bundle.getString("Driver");
    final String DATABASE_URL = bundle.getString("URL");
    final String USERNAME = bundle.getString("User");
    final String PASSWORD = bundle.getString("Password");
    // default query retrieves all data from authors table
    //static final String DEFAULT_QUERY = "SELECT authors.lastName, authors.firstName, titles.title, titles.editionNumber FROM titles INNER JOIN (authorISBN INNER JOIN authors ON authorISBN.authorID=authors.authorID) ON titles.isbn=authorISBN.isbn";
    final String DEFAULT_QUERY = bundle.getString("Query");
    private ResultSetTableModel tableModel;
    private JTextArea queryArea;
    static final int xOffset = 0, yOffset = 200;
    private boolean ALLOW_COLUMN_SELECTION = false;
    private boolean ALLOW_ROW_SELECTION = true;
    // create ResultSetTableModel and GUI
    public DisplayQueryResults() {  
    super("Sales of the Day",
    true, //resizable
    true, //closable
    true, //maximizable
    false);//iconifiable
    //...Create the GUI and put it in the window...
    //Set the window's location.
    setLocation(xOffset, yOffset);
    // create ResultSetTableModel and display database table
    try {
    // create TableModel for results of query SELECT * FROM authors
    tableModel = new ResultSetTableModel(JDBC_DRIVER, DATABASE_URL,
    USERNAME, PASSWORD, DEFAULT_QUERY);
    // set up JTextArea in which user types queries
    queryArea = new JTextArea(DEFAULT_QUERY, 1, 100);
    queryArea.setWrapStyleWord(true);
    queryArea.setLineWrap(true);
    JScrollPane scrollPane = new JScrollPane(queryArea,
    ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
    ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    // set up JButton for submitting queries
    JButton submitButton = new JButton("Submit Query");
    // create Box to manage placement of queryArea and
    // submitButton in GUI
    Box box = Box.createHorizontalBox();
    box.add(scrollPane);
    box.add(submitButton);
    // create JTable delegate for tableModel
    JTable resultTable = new JTable(tableModel);
    resultTable.setFillsViewportHeight(true); // Makes the empty space heights white
    resultTable.setRowSelectionAllowed(true);
    resultTable.getModel().addTableModelListener(this); // step 3
    // place GUI components on content pane
    add(box, BorderLayout.NORTH);
    add(new JScrollPane(resultTable), BorderLayout.CENTER);
    // create event listener for submitButton
    submitButton.addActionListener(
    new ActionListener()
    // pass query to table model
    public void actionPerformed(ActionEvent event)
    // perform a new query
    try
    tableModel.setQuery(queryArea.getText());
    } // end try
    catch ( SQLException sqlException)
    JOptionPane.showMessageDialog(null,
    sqlException.getMessage(), "Database error",
    JOptionPane.ERROR_MESSAGE);
    // try to recover from invalid user query
    // by executing default query
    try {
    tableModel.setQuery(DEFAULT_QUERY);
    queryArea.setText(DEFAULT_QUERY);
    } // end try
    catch (SQLException sqlException2) {
    JOptionPane.showMessageDialog(null,
    sqlException2.getMessage(), "Database error",
    JOptionPane.ERROR_MESSAGE);
    // ensure database connection is closed
    tableModel.disconnectFromDatabase();
    System.exit(1); // terminate application
    } // end inner catch
    } // end outer catch
    } // end actionPerformed
    } // end ActionListener inner class
    ); // end call to addActionListener
    //...Then set the window size or call pack...
         setSize(750,300);
    setVisible(true); // display window
    } // end try
    catch (ClassNotFoundException classNotFound) {
    JOptionPane.showMessageDialog(null,
    "MySQL driver not found", "Driver not found",
    JOptionPane.ERROR_MESSAGE);
    System.exit(1); // terminate application
    } // end catch
    catch (SQLException sqlException) {
    JOptionPane.showMessageDialog(null, sqlException.getMessage(),
    "Database error", JOptionPane.ERROR_MESSAGE);
    // ensure database connection is closed
    tableModel.disconnectFromDatabase();
    System.exit(1); // terminate application
    } // end catch
    // dispose of window when user quits application (this overrides
    // the default of HIDE_ON_CLOSE)
    setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    // ensure database connection is closed when user quits application
    addInternalFrameListener(
    new InternalFrameAdapter() {
    // disconnect from database and exit when window has closed
    public void windowClosed(WindowEvent event) {
    tableModel.disconnectFromDatabase();
    System.exit(0);
    } // end method windowClosed
    } // end WindowAdapter inner class
    ); // end call to addWindowListener
    } // end DisplayQueryResults constructor
    public void tableChanged(TableModelEvent e) { // step 4
    int row = e.getFirstRow();
    int column = e.getColumn();
    TableModel model = (TableModel)e.getSource();
    String columnName = model.getColumnName(column);
    Object tableModel = model.getValueAt(row, column);
    // Do something with the data...
    System.out.println(tableModel);
    System.out.println("data");
    // execute application
    public static void main(String args[]) {
    new DisplayQueryResults();
    } // end main
    } // end class DisplayQueryResults
    My question is in lines 177-187:
    public void tableChanged(TableModelEvent e) { // step 4
    int row = e.getFirstRow();
    int column = e.getColumn();
    TableModel model = (TableModel)e.getSource();
    String columnName = model.getColumnName(column);
    Object tableModel = model.getValueAt(row, column);
    // Do something with the data...
    System.out.println(tableModel);
    System.out.println("data");
    Why is my listener not working or why is it not implemented when I click the cells in the JTable and why is it not reflected into the JTable or into the console?
    If this is Flash, Things can be done easily, but this is Java, and I dont know much about this language. I admit that I am new to this -intirely new.
    PS:
    When you have solved the problem, please notify me with the code that's changed
    and please share it to others if you like so.
    Best Wishes: Oliver Bob Lagumen
    Email: [email protected]
    website: www.apachevista.com
    Oliver Bob Lagumen
    Edited by: Oliverbob on Jan 24, 2008 9:03 PM

    This is a follow up on the code I have posted above.
       public void tableChanged(TableModelEvent e) { // step 4
            int row = e.getFirstRow();
            int column = e.getColumn();
            TableModel model = (TableModel)e.getSource();
            String columnName = model.getColumnName(column);
            Object tableModel = model.getValueAt(row, column);
            // Do something with the data...
            System.out.println(tableModel);
            System.out.println("data");
        }the tableChanged doesnt get called when I would click the cells. The cells are all editable, but as soon as you edit it and press enter, it snaps back to the old data.
    How do we make them editable and how do we notify java that the a cell has changed so that we can send it to the database on that specific column of that specific row?
    Thanks in advance
    Bob

  • HTML select tag on irpt page - update database from options

    Hi all,
    I have an irpt page with two selects.  It is the traditional move stuff from one select to the other, then set the order of the options in the configured select.  (Admin page to specify an ordered list of items)
    After the user gets the list how they want it, I would like to send the options to an MII transaction (iCommand?) to update the database table that backs this admin data.
    I can do a comma delimited string to hold the select tag's option values, but would like to know if there is a more elegant way!
    Ideas?
    Thanks,
    --Amy Smith
    --Haworth

    It sounds elegant already - a pretty simple javascript loop to build your csv and Param.1 to your iCommand applet query should work like a charm.
    If you need to run it to a TRX, then the StringListToXML action makes turning your csv into linkable properties a simple effort.

  • Remove record in database from Jtable?

    I want to delete row in databse, but don't know how to add field to primary key Jtable like hidden field,
    Can you show me or any difference way to solve this?

    There are two ways to hide a column (that I know of):
    1) Set the columns widths to 0. I don't like this approach because because the 'hidden' column still requires a tab.
    2) Remove the TableColumn from the TableColumnModel. This is my preferred approach.
    Here is a simple example using both approaches, You determine which approach you like best:
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.table.*;
    public class TableColumnHide extends JFrame
         public TableColumnHide()
              String[] columnNames = {"Identifier", "Student#", "Student Name", "Gender", "Grade", "Average"};
              Object[][] data =
                   {new Integer(1), "Bob",   "M", "A", new Double(85.5) },
                   {new Integer(2), "Carol", "F", "B", new Double(77.7) },
                   {new Integer(3), "Ted",   "M", "C", new Double(66.6) },
                   {new Integer(4), "Alice", "F", "D", new Double(55.5) }
              DefaultTableModel model = new DefaultTableModel(data, columnNames);
              //  Hide column by setting minimum width
              JTable table1 = new JTable(model);
              table1.getColumnModel().getColumn(0).setMinWidth(0);
              table1.getColumnModel().getColumn(0).setPreferredWidth(0);
              table1.setPreferredScrollableViewportSize(table1.getPreferredSize());
              JScrollPane scrollPane1= new JScrollPane( table1 );
              getContentPane().add( scrollPane1, BorderLayout.WEST );
              //  Remove columns from TableColumnModel
              JTable table2 = new JTable(model);
              TableColumnModel columnModel2 = table2.getColumnModel();
              columnModel2.removeColumn( columnModel2.getColumn( 0 ) );
              table2.setPreferredScrollableViewportSize(table2.getPreferredSize());
              JScrollPane scrollPane2 = new JScrollPane( table2 );
              getContentPane().add( scrollPane2, BorderLayout.EAST );
              JPanel north = new JPanel( new GridLayout(1, 2) );
              north.add( new JLabel("Width = 0") );
              north.add( new JLabel("Remove Table Column") );
              getContentPane().add(north, BorderLayout.NORTH );
         public static void main(String[] args)
              TableColumnHide frame = new TableColumnHide();
              frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
              frame.pack();
              frame.setVisible(true);
    }Since we 'hid' the first column, try tabbing from the last column to the first. Notice which approach requires 2 tabs before the appropriate cell gets highlighted.

  • How to update database using Service in 11g

    Please some one provide the knowledge, how i will update database from a form and form is having multiple rows and column and and all are having different or same value.
    e.g. we have having clientName table and having column(clientname, legalContact, selfservice,usertype,details),
    We can search the data from clientName, now user can change other information except clientName can not be change but other information can change. now how i will update users changed value.

    Hi ,
    If you are looking to update the fields for a user such as description , telephone number etc then the following service needs to be used :
    UPDATE_USER_META_TABLE
    Details for this are available in : http://docs.oracle.com/cd/E23943_01/doc.1111/e11011/c04_core.htm#CSSRG2503
    Hope this helps .
    Thanks,
    Srinath

  • Insert and update tables from SQL server to oracle database tables

    Hi,
    I am having problem while update data from sql server to oracle database tables.
    I am doing one way insert +updates that is from SQL Server tables ==> Oracle database tables
    I am using tools Sql server Integration service. I can insert data from sql server to oracle but update can't. Please help me how can I update + insert from sql server to oracle database tables easily.
    Thanks in advance.

    Hi,
    What about using Oracle SQL Developer for migration
    http://www.oracle.com/technetwork/database/migration/sqlserver-095136.html
    HTH

  • Making a jtable auto updates itself from a mysql table

    Pretty much what the title says. How can i auto update the jtable for every time my mysql table is updated in anyway? i am implementing this auto update function in my admin program which displays a list of users who are online etc. from the moment a user is offline/online or changes other details displayed in my jtable, i want it to auto update the jtable as soon as the actual mysql table has been updated with new data...
    I was thinking of re doing the whole jtable i made and create a thread for that table that has a infinite while loop that keeps repainting the jtable with the new updated data from a mysql table query eg select * from table and store the data into a resultset which then gets transferred into a vector. Load the vector into the jtbale and their ya go�.
    what you think of this approach? Is their a better way to do this?
    at the moment, as soon as my application opens, the jtable views all the data from my sql table, however if it doesnt auto updates itself, cheers

    i am implementing this auto update
    function in my admin program which displays a list of
    users who are online etc. from the moment a user is
    offline/online or changes other details displayed in
    my jtable, i want it to auto update the jtable as
    soon as the actual mysql table has been updated with
    new data...Well you can make some changes to make implementation easy
    Ex: Create a table to keep a log of the changes in the system the dmin program read the log and replicate the changes as specified in the log on the table model.
    When reading the log the admin program keep track of the sequence no of the last read log entry and it reads ony the entries which has larger seq numbers than the last read seq no
    I dont think that it is critical to make this to be cloase to real time. An Update once a 1 or 2 secs should be sufficient.

  • Connecting and Updating External Database from SAP

    Connecting and Updating External Database from SAP
    How can i connect SAP Database to External database?
    How can i update external databas from SAP withouting using BI/BW, Workflow or Net Weaver?
    If anyone know please let me inform.
    Thanks in Advance.
    Jahnavee Trivedi

    Steps
    1. Create an entry in tnsnames.ora for the remote oracle DB
    2. Test sqlplus user/pass@remote 
    3. create a synonym which points to a table at remote DB check docs.oracle.com
    4. user ABAP code execute SQL to insert data into local synonym which inturn updates the remote DB.
    I have done this in the past, it works great.
    It requries, DBA skills + ABAP programming
    -AJ

  • Best way to update DR database from PROD server automatic ?

    Hello Gurus,
    I want to decide best solution.
    Goal: Best way to update DR Database from PROD Server Database automatic.
    System: 32 bit Linux system with Oracle Database 10g Release 10.2.0.4.0 - Production (database version) Oracle version is standard.
    Please let me know how i can update my DR server with PROD data and this task should be automatic.
    Please ask me more information if required to solve this issue.
    Thanks- Priyank
    Edited by: Oracle DBA P on Nov 19, 2010 3:06 AM

    you mean to say data guard needs to implement ? i think that's one option but what you said is different ?
    tell me procedure how i can implement your idea ? steps i have to perform.
    Thanks
    Edited by: Oracle DBA P on Nov 19, 2010 3:38 AM

  • Update database table from a work area

    hi!
    I have a workarea that is like the corresponding database table. There are a lot of fields so I dont want to update each field with an UPDATE but instead I want to do som sort of:
    UPDATE dbase_table
    FROM work_area
    WHERE dbase_table-primary_key = work_area-primary_key
    I could only find a statement called UPDATE dbase_table FROM  work_area but I dont understand how without specifying a WHERE clause it knows which rows to update.
    regards
    Baran

    UPDATE  dbtab      FROM wa. or
    UPDATE (dbtabname) FROM wa.
    Extras:
    1. ... CLIENT SPECIFIED
    2. ... CONNECTION con
    Effect
    Changes one single line in a database table, using a primary key to identify the line and taking the values to be changed from the specified work area, wa. The data is read out of wa from left to right, matching the line structure of the database table dbtab. The structure of wa remains unchanged. This means that wa must be at least as wide (see DATA) as the line structure of dbtab, and have the same alignment. Otherwise, a runtime error occurs.
    If either the database table, dbtab, or the work area, wa, contain Strings, wa must be compatible with the line structure of dbtab.
    Example
    Changing the telephone number of the customer with customer number '12400177' in the current client:
    DATA   wa TYPE scustom.
    SELECT SINGLE * FROM scustom INTO wa
      WHERE id = '12400177'.
    wa-telephone = '06201/44889'.
    UPDATE scustom FROM wa.
    When the command has been executed, the system field SY-DBCNT contains the number of updated lines (0 or 1).
    Examples
    Update discount for the customer with the customer number '00017777' to 3 percent (in the current client):
    DATA: wa TYPE scustom.
    SELECT SINGLE * FROM scustom INTO wa
      WHERE id = '00017777'.
    wa-discount = '003'.
    UPDATE scustom FROM wa.
    The Return Code is set as follows:
    SY-SUBRC = 0:
    The specified line has been updated.
    SY-SUBRC = 4:
    The system could not update any line in the table, since there is no line with the specified primary key.
    BR< JAcek

  • How to update database table from Internal Table

    hi experts,
        Can anyone please assist me in inserting records to a database table from an Internal Table
    whose structures are identical.
    Thanks in Advance,
    Sudhaa............

    Hi Sudha,
    Here are some example of update and insert:
    UPDATE SFLIGHT SET PLANETYPE = 'A310'
    PRICE = PRICE - '100.00'
    WHERE CARRID = 'LH' AND CONNID = '0402'.
    This example overwrites the contents of the PLANETYPE column with A310 and decreases the value of the PRICE column by 100 for each entry in SFLIGHT where CARRID contains u2018LHu2019 and CONNID contains u2018402u2019.
    TABLES SPFLI.
    DATA WA TYPE SPFLI.
    MOVE 'AA' TO WA-CARRID.
    MOVE '0064' TO WA-CONNID.
    MOVE 'WASHINGTON' TO WA-CITYFROM.
    UPDATE SPFLI FROM WA.
    MOVE 'LH' TO SPFLI-CARRID.
    MOVE '0017' TO SPFLI-CONNID.
    MOVE 'BERLIN' TO SPFLI-CITYFROM.
    UPDATE SPFLI.
    CARRID and CONNID are the primary key fields of table SPFLI. All fields of those lines where the primary key fields are "AA" and "0064", or "LH" and "0017", are replaced by the values in the corresponding fields of the work area WA or the table work area SPFLI.
    DATA: ITAB TYPE HASHED TABLE OF SPFLI
    WITH UNIQUE KEY CARRID CONNID,
    WA LIKE LINE OF ITAB.
    WA-CARRID = 'UA'. WA-CONNID = '0011'. WA-CITYFROM = ...
    INSERT WA INTO TABLE ITAB.
    WA-CARRID = 'LH'. WA-CONNID = '1245'. WA-CITYFROM = ...
    INSERT WA INTO TABLE ITAB.
    WA-CARRID = 'AA'. WA-CONNID = '4574'. WA-CITYFROM = ...
    INSERT WA INTO TABLE ITAB.
    UPDATE SPFLI FROM TABLE ITAB.
    This example fills a hashed table ITAB and then overwrites the lines in SPFLI that have the same primary key (CARRID and CONNID) as a line in the internal table.
    Insert statement :
    TABLES SPFLI.
    DATA WA TYPE SPFLI.
    WA-CARRID = 'LH'.
    WA-CITYFROM = 'WASHINGTON'.
    INSERT INTO SPFLI VALUES WA.
    WA-CARRID = 'UA'.
    WA-CITYFROM = 'LONDON'.
    INSERT SPFLI FROM WA.
    SPFLI-CARRID = 'LH'.
    SPFLI-CITYFROM = 'BERLIN'.
    INSERT SPFLI.
    If the database table does not already contain a line with the same primary key as specified in the work area, the operation is completed successfully and SY-SUBRC is set to 0. Otherwise, the line is not inserted, and SY-SUBRC is set to 4.
    Regards,
    Premraj kaushik

  • Update 2 different databases from Timesten cache

    Is it possible to udpate 2 different databases from a single Timesten configured cache?.
    Edited by: user6867140 on Feb 12, 2009 1:06 PM

    Two different oracle instances.
    Let me give an example
    Table A is present in Oracle database 1
    Table B is present in Oracle database 2
    Table A is cached in TimesTen
    Any change in Table A in timesten need to be updated in Table A of Oracle database 1 and Table B of Oracle database 2
    Table A and Table B has the same data structure.

Maybe you are looking for

  • At a loss with phone line

    Firstly I am stating for the record that I have a problem with my phone line. My broadband issues are just a by-product of the phone line fault. This problem has been going on for several years, although, 2 months ago i made some progress. The proble

  • Can I transfer money from on apple id account to another?

    I made an apple id account, but forgot the security questions. So I made another, but I need the money off another to buy music.

  • Help to read a table with data source and convert time stamp

    Hi Gurus,   I have a req and need to write a ABAP prog. As soon as i excute ABAP program it should ask me enter a data source name, then my ABAP prog has excute teh code, in ABAP code i have to read a table with this data source as key, sort time sta

  • DSO activation failed due to creation of the export datasource failed

    hi experts, i am activating DSO, but failed. Cause is "The creation of the export DataSource failed" there are many threads in the forum saying restoring the BI myself source system can address it, I tried many times, but failed. I used program RSDG_

  • Document type for outgoing Excise invoice

    Dear Expert, I would like to maintain different document type for Excise document generated at the time of J1IIN transaction. At present system generating document type SA. So we need to maintain different number range for these documents instead of