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 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 java.io.*;
import java.net.*;
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()
{
super();
initializeComponent();
this.setVisible(true);
}
private void initializeComponent()
{
jLabel1 = new JLabel();
jButton1 = new JButton();
jTextField1 = new JTextField(20);
//jTextField1.setName("att");
contentPane = (JPanel)this.getContentPane();
contentPane.setBackground(Color.pink);
jLabel1.setText("ATTENDANCE");
jButton1.setText("Submit");
try{
Connection con = null;
Class.forName("com.mysql.jdbc.Driver");
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 (rs.next()) {
row = new Vector(columns);
for (int i = 1; i <= columns; i++)
{
row.addElement( rs.getObject(i));
if(i==4)
{
row.addElement(jTextField1);
}
}
data.addElement( row );
//
}
String k=jTextField1.getText();
System.out.println(k);
rs.close();
st.close();
}
catch(Exception e) {}
JTable table = new JTable(data, columnNames);
JScrollPane scrollPane = new JScrollPane( table );
contentPane.setLayout(null);
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();
//System.out.println(data.get(2));
//System.out.println(row.elementAt(3));
//g=data.get(4);
//System.out.println(g);
try{
int i;
String sql=null;
Connection con = null;
//ResultSet rs=null;
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost/vinay", "root", "admin");
if(con!=null)
{
System.out.println("connectin established");
}
Statement st = con.createStatement();
for(i=3;i>0;i-=3)
{
System.out.println(row.get(i));
String a=(String) row.get(i);
Pattern p=Pattern.compile("^p");
Matcher m=p.matcher(a);
if(m.find())
{
sql="update student set attend='"+a+"'";
System.out.println(sql);
st.executeUpdate(sql);
}
}
st.close();
con.close();
}
catch(Exception e1) {}
}
});
}
private void addComponent(Container container,Component c,int x,int y,int width,int height)
{
c.setBounds(x,y,width,height);
container.add(c);
}
}
View Answers
February 3, 2011 at 12:33 PM
Related Tutorials/Questions & Answers:
Swings and JDBCSwings 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 Beginnershow 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
Advertisements
SWINGSSWINGS WHAT ARE THE DIFFERENCES BETWEEN AWT AND
SWINGS java code using swingsjava 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 questionswings question how to change the background color with the help of color values by using
swings swings for webnmsswings 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 JTableSwings JTable add values to JTable with four coloums,two of them are comboboxes
Swings & JSPSwings & 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
Java SwingsJava 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 headerswings 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
swings","J","K","L","M","N","O","P","
Q","R","S","T","U","V","W","X","Y","Z"};
for(i = 0
Swings - AppletSwings 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
Swings/awt - Swing AWTSwings/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 java swings - Java Beginnersjava
swings Hi,
I need the code for click the refresh button then list values will be refresh.Please send the code ...........
Thanks,
Valarmathi
Beans in Swings tableBeans 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...("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("
jdbc:mysql
about swings - Java Beginnersabout swings Dear sir,Good evening,
i am doing mca sir,i am doing the project in
swings,so plz provide the material about
swings sir
Thank you Hi Friend,
Please visit the following link
JDBCJDBC why we use batch in
jdbc jdbcjdbc display the records using index in
jdbc jdbcjdbc Hai ,
Give a steps for
jdbc connectivity
java swings - Java Beginnersjava
swings Hi,
I need the code for joptionpane with jcombobox.
my requirement is click on add button,one joptionpane will come.from the option pane i need to select the combobox values.
Please send the sample code
JDBCJDBC How to add set of queries in a single query in
JDBC swings - Java Beginnersswings how t upload images in
swings.
thanks
Hello Friend,
Try the following code:
import java.io.*;
import java.sql....);
try{
Connection con = null;
String url = "
jdbc:mysql
java swings - Swing AWTjava swings I am doing a project for my company. I need a to show the performance of the employees by using bar bharts. Please give me how can we write the code for bar charts using java
swings. Hi friend,
I am
swings window headerswings window header i have a string1 it contains 3 parts,for example "123456 service hello"
and string2 contains "change request " like this.
and the string3 should contain "123456 "........." hello"
".........." can
jdbc jdbc how to write program to save data and retrieve data from the form in Java
jdbcjdbc why do we need to load
jdbc drivers before connecting to database
JDBCJDBC how to set classpath for eclipse, java, where to copy
jdbc connector
JDBCJDBC in class.forname which driver name we are writing for the connection from
jdbc to sqlserver 2008
jdbcjdbc is it possible to use doget & dopost method with
jdbc to call in a servlet programe
JdbcJdbc A java program with
jdbc connectivity with insert,delete,update options for name,regno,mark1,mark2,total
JDBCJDBC can u send me the code of
jdbc how to join two tables that are in relation
jdbcjdbc please tell me sir.i dont know
JDBC connection and how to create table in database
JDBC - JDBCJDBC - limitations of jdbc What are the limitations of
JDBC jdbcjdbc define batch updates define batch updates?exp
JDBC... links:
http://www.roseindia.net/
jdbc/
Jdbc-batch-update.shtml
http://www.roseindia.net/tutorial/java/
jdbc/batchupdateresultsetexample.html