Beans in Swings table

Beans in Swings table

Hi Sir/Madam....

I am Trying Develop an Swing from which include an table which displays the data from mysql table and i am adding one Jtextfield in each row in the last column and i want to update the table with that textfield values...

The thing is it will be having multiple values so i decided to use beans but the value which i am entering in textfield is not getting read by getText() method...

Can any one please help in solving this problem please...

View Answers

January 5, 2011 at 1:13 PM

Hi Friend,

Try the following code:

import java.io.*;
import java.awt.*;
import java.sql.*;
import java.util.*;
import javax.swing.*;

class JTableDatabase extends JFrame{
    ResultSet rs;
    JTableDatabase(){
    final Vector columnNames = new Vector();
        final Vector data = new Vector();
      JPanel panel=new JPanel();
      try{
    Class.forName("com.mysql.jdbc.Driver");
     Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
        Statement st = con.createStatement();
        ResultSet rs= st.executeQuery("Select * from employee");
    ResultSetMetaData md = rs.getMetaData();
int columns = md.getColumnCount();
for (int i = 1; i <= columns; i++) {
columnNames.addElement( md.getColumnName(i) );
}
while (rs.next()) {
Vector row = new Vector(columns);
for (int i = 1; i <= columns; i++) {
row.addElement( rs.getObject(i) );
}
data.addElement( row );
}
}
catch(Exception e){}
JTable table = new JTable(data, columnNames);
JScrollPane scrollPane = new JScrollPane(table);
panel.add(scrollPane);
add(panel);
}
 public static void main(String arg[])
  {
    try
    {
    JTableDatabase frame=new JTableDatabase();
    frame.setSize(550,200);
    frame.setVisible(true);
    }
  catch(Exception e)
    {}
  }
}

Thanks









Related Tutorials/Questions & Answers:
Beans in Swings table
Beans in Swings table  Hi Sir/Madam.... I am Trying Develop an Swing from which include an table which displays the data from mysql table and i am... the table with that textfield values... The thing is it will be having multiple
how to display a table and buttons in swings - Java Beginners
how to display a table and buttons in swings  Hi frends, Actually i want to display a table during runtime and at the same time i also want to add different buttons below this displayed table using swings.....please can any
Advertisements
how to display a table and buttons in swings - Java Beginners
how to display a table and buttons in swings  Hi frends, Actually i want to display a table during runtime and at the same time i also want to add different buttons below this displayed table using swings.....please can any
how to enter matrix data into a table of swings - Java Beginners
how to enter matrix data into a table of swings   Hi frends, I want to display a matrix data into a particular table...... Actually if the user... and insert the data into that table using swings...........matrix can be anything
SWINGS
SWINGS  WHAT ARE THE DIFFERENCES BETWEEN AWT AND SWINGS
how can i draw a table using applet or swings - Java Beginners
how can i draw a table using applet or swings  Hi RoseIndia, Actually, I was trying for creating a table using applet or swings.......... My task is create a table and enter the integer values during run time......I have
how to store data in table using swings - Java Beginners
how to store data in table using swings  Hi, I am doing a project in which i need to store some data in the table using swings.......Iam using... , whether do i have any option in swings to increase my output look (my target
JSP & Swings
JSP & Swings  How to integrate jsp and swings
swings question
swings question  how to change the background color with the help of color values by using swings
swings for webnms
swings for webnms  if i am expanding node of jtree then i want to collapse previous expanding node of jtree in swings how is it possible
Swings JTable
Swings JTable  add values to JTable with four coloums,two of them are comboboxes
table
table  multiplicatyion table
Swings & JSP
Swings & JSP  Hai all, Can we use Swing components in a JSP?? Suppose if we enter details in a swing dialog box..and If we want the result in a JSP..is that possible??? Thank you
TABLE
TABLE   Why doesn't <TABLE WIDTH="100%"> use the full browser width
Swings and JDBC
Swings and JDBC  Hi.. I am vinay.. I am developing a small application using swings and mysql. I am sending part of the code here.. The problem is i...(); } catch(Exception e) {} JTable table = new JTable(data, columnNames
Table
Table  How i generate table in showMessageDialog. I want that i creat a table and run in showMessageDialogeprint("cprint("code sample");ode sample
Java Swings
Java Swings  I am doing one project on java Swings, in this i have created one jframe where i defined some JButtons and Jcombobox's, here i need to insert one JTable with headers(IN CURRENT JFrame only).pls help me urgently
Table
Table  How I generate table in showMessageDialog. E.g 3X1=3 3X2=6 3X3=9print("code sample
Table
Table  How i generate table in showMessageDialog. I want to creat a table and run in showMessageDialoge. Pl make a table programe which run..., JOptionpane, Integer.parseInt. Please use only these above methods to make table
table
input from oracle table(my database table..) This is a very important table of my
table
table  Hi..I have a list of links which links to a table in the same page.If I click first link the table is displayed at the top, likewise if i click the last link the table is displayed at the last,i dont know how to set
Table
Table  How i generate table in JOptionpane.showMessageDialog... advance coding but i want u make the table using JOptionpane.showMessageDialog, import.javax.swing int Integer.parseInt(). Thats my limit. Pl generata a table
swings header
swings header   have a string1 it contains 3 parts,for example "123456 service hello" and string2 contains text "change request " like this. and the string3 should contain "123456 +(second string)+ hello" "second string can
table?
table?  Hi, how could i make a table in javascript, which would look like this: AA CODON Number /1000 Fraction .. (this row... can't figure out, how to construct a table,with two fixed columns, one that reads
Table
Table  Why u dont understand sir?? I want to make a table program which generate a table on showMessageDialog. I have learnt these methods until now... methods to be used. Write a table program which use only and only these above methods
Table
Table  How i create table on showMessageDialog using JOptionpane and Integer.parseInt. No other method to use. Pl make a program which generate 5X1=5 5X2=10 5X3=15   Hi Friend, Try this: import javax.swing.*; import
swings
","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"}; for(i = 0
swings
swings
swings
swings
swings
swings
Java Beans
Java Beans  hii What is Java Beans?   hello,,ADS_TO_REPLACE_1 A Java Bean is a reusable software component that can be manipulated visually in a builder tool
net beans
net beans  how to calculate electric bill,units,load in net beans and how to insert this calculated bill ,unit and load into database and how this calculate value comes on GUI
net beans
net beans  how to calculate electric bill,units,load in net beans and how to insert this calculated bill ,unit and load into database and how this calculate value comes on GUI
net beans
net beans  how to calculate electric bill,units,load in net beans and how to insert this calculated bill ,unit and load into database and how this calculate value comes on GUI
net beans
net beans  how to calculate electric bill,units,load in net beans and how to insert this calculated bill ,unit and load into database and how this calculate value comes on GUI
net beans
net beans  how to calculate electric bill,units,load in net beans and how to insert this calculated bill ,unit and load into database and how this calculate value comes on GUI
net beans
net beans  how to calculate electric bill,units,load in net beans and how to insert this calculated bill ,unit and load into database and how this calculate value comes on GUI
Swings - Applet
Swings  Sir, I have developed an application in swings i want to call that class in applet. is it possible. or otherwise is there any way to deploy java class in browser. Give an example... Thanks in advance...  Hi
NET BEANS
NET BEANS  My problem is when i am going to install net beans then it showing the problem that JDK6 or JDK5 is required for installing net beans IDE,but in actually I've already installed the jdk5,I do not know why
java swings - Java Beginners
java swings   Do you want to add textfields on the JPanel
Image Movement using Swings
Image Movement using Swings  How to move image using Swings
how to create frame in swings
how to create frame in swings  how to create frame in swings
Version of gj-beans>gj-beans dependency
List of Version of gj-beans>gj-beans dependency
Swings/awt - Swing AWT
Swings/awt  Hi, how to write action listeners to the Buttons in RichTextEditor tool bar.. thanks in advance...it's Urgent... i am very much new to Swings
Display data from xml file to Swings - Swing AWT
Display data from xml file to Swings  Hi, We are Preparing a stand alone application. Where the Swings is the front end. There will be only... clicking the buttons in swings it has to display 20 record in one shot in table
Enterprise Beans
Enterprise Beans       Enterprise beans are the Java EE server side components that run inside the ejb container... by many users. Enterprise beans are used to perform various types of task like
java swings - Java Beginners
java swings   Hi, I need the code for click the refresh button then list values will be refresh.Please send the code ........... Thanks, Valarmathi

Ads