Share on Google+Share on Google+

Vinay KP
Swings and JDBC
1 Answer(s)      6 years and 2 months ago
Posted in : Java Beginners

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 need to update the mysql fields with values which are gettin from dynamiclly created JTextfields... but i am not getting how i can fetch those particular values and update database with those value.....

Please help me..

My work is paused here... please

Here the code....

package kp;

import java.awt.*; import java.util.regex.*;

import java.awt.event.*;

import javax.swing.*;

import*; import*; import java.util.*; import java.sql.*; import java.lang.*; public class attend extends JFrame{

private JLabel jLabel1;
private JButton jButton1;
private JTextField jTextField2;
private JPanel contentPane;
private JTextField jTextField1;
final Vector columnNames = new Vector();
final Vector data = new Vector();
Vector row;
final Object g=new Vector();

public attend()



private void initializeComponent()
    jLabel1 = new JLabel();
    jButton1 = new JButton();
    jTextField1 = new JTextField(20);
    contentPane = (JPanel)this.getContentPane();


        Connection con = null;
        con = DriverManager.getConnection("jdbc:mysql://localhost/vinay", "root", "admin");
        Statement st = con.createStatement();
        ResultSet rs= st.executeQuery("Select * from student");
        ResultSetMetaData md = rs.getMetaData();
        int columns = md.getColumnCount();
        for (int i = 1; i <= columns; i++) 
        columnNames.addElement( md.getColumnName(i) );
        while ( {
        row = new Vector(columns);
        for (int i = 1; i <= columns; i++) 
            row.addElement( rs.getObject(i));

        data.addElement( row );

        String k=jTextField1.getText();
        catch(Exception e) {}
        JTable table = new JTable(data, columnNames);
        JScrollPane scrollPane = new JScrollPane( table );
    addComponent(contentPane, scrollPane, 5,110,200,200);
addComponent(contentPane, jLabel1, 50,1,345,37);
addComponent(contentPane, jButton1, 220,300,100,28);
this.setTitle("Class Attendance");
this.setLocation(new Point(66, 48));
this.setSize(new Dimension(438, 384));

jButton1.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e)
        Vector z=new Vector();
            int i;
            String sql=null;
            Connection con = null;
            //ResultSet rs=null;
            con = DriverManager.getConnection("jdbc:mysql://localhost/vinay", "root", "admin");
            System.out.println("connectin established");
            Statement st = con.createStatement();
                 String a=(String) row.get(i);
                Pattern p=Pattern.compile("^p");
                Matcher m=p.matcher(a);
            sql="update student set attend='"+a+"'";

            catch(Exception e1) {}


private void addComponent(Container container,Component c,int x,int y,int width,int height)



View Answers

February 3, 2011 at 12:33 PM

Hi Friend,

Please visit the following link:

Add Edit Delete Application

Hope that it will be helpful for you.


Related Tutorials/Questions & Answers:
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...("com.mysql.jdbc.Driver"); con = DriverManager.getConnection("jdbc:mysql://localhost/vinay
how to connect swings with jdbc... - Java Beginners
how to connect swings with jdbc...  Hi friends, Is it possible, to connect swings with data base like oracle....i want to store data into database... by using servlets and jsp but is it possible by using swings........ for data base
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
java code using swings
java code using swings  code that should be able to enter data of student details using all swings into the access database using jdbc connectivity
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
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 that possible??? Thank you
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
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
","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"}; for(i = 0
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
how to create frame in swings
how to create frame in swings  how to create frame in swings
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
Swings/awt - Swing AWT
Swings/awt  Hi, how to write action listeners to the Buttons in RichTextEditor tool bar.. thanks in's Urgent... i am very much new to Swings
jdbc  display the records using index in jdbc
jdbc  Hai , Give a steps for jdbc connectivity
JDBC  why we use batch in jdbc
JDBC  How to add set of queries in a single query in JDBC
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
JDBC  can u send me the code of jdbc how to join two tables that are in relation
Java Spring Hibernate Struts Training What does core Java include? java What are some way to learn Java quickly? Is it required to learn Java before learning Java Script? Is it necessary to learn java script before learning PHP? Are HTML5 and Java Script boosts Java career? Is Java object oriented? Fingerprint application with Java Uninstall Oracle Virtual Box JSON to HashMap Free Java online Training I want example of Control Statement in Java ANSI Color Codes with Python Create a Program that Calculates Input What is difference between JDK,JRE and JVM? How to see ubuntu version on server? How to get Page Source in Selenium (WebDriver) using Java? The path to the driver executable must be set by the webdriver.gecko.driver system property parse data from a link in java Java Program Qns using BlueJ How to fix HAX Kernel Module Is Not Installed error? Installing Audacity Looking for code Logic to check track changes & Coments in MSWord, MSWordx, MSExcel, MSExcelx is ON/OFF Installing JDK on Mac SAX Parser exception ERROR 601 (42P00): Syntax error. Encountered Thread java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileItemFactory How to install Ubuntu 16.04 LTS? HttpServletRequest cannot be resolved to a type in eclipse - Solved Unhandled event loop exception GC overhead limit exceeded Spring Data jpa with apache phoenix Caused by: java.lang.IllegalArgumentException: Not a host:port pair: PBUF o.a.h.h.z.RecoverableZooKeeper - Possibly transient ZooKeeper, quorum= com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager class not found com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager not found How to download and install Java 8 on Windows? How to uninstall JDK 7? How to install gtk-doc-tools package in Ubuntu? How to install Oracle JDK 8 on Ubuntu? ejabberd_ctl.beam not found - Solved How to convert date to UTC format in Java? How to install autoconf, automake and libtool in Ubuntu 15.10? How to convert current date to mm dd yyyy format in Java? How to convert current date to dd mm yyyy format in Java? How to stop window closing in "internalFrameClosing" event. How to find list of all index in Neo4j? file location SASLError using PLAIN: not-authorized how to convert war file into .exe file using java code


Advertisement null