import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
/*
<applet code="JtextFieldDemo3" width=300 height=200>
</applet>
*/
public class JtextFieldDemo3 extends JApplet
{
JLabel jlb1,jlb2,jlb3,jlb4,jlb5;
JTextField jtf1,jtf2,jtf3,jtf4,jtf5;
JButton jb;
String text1,text2,text3,text4,text5;
public void init()
{
try
{
SwingUtilities.invokeAndWait(new Runnable(){
public void run()
{
makeGUI();
}
});
}catch(Exception e)
{ System.out.println(e);
}
}
private void makeGUI()
{
setLayout(new FlowLayout());
jlb1=new JLabel("regester_no");
jtf1=new JTextField(20);
jlb2=new JLabel("student name");
jtf2=new JTextField(20);
jlb3=new JLabel("father name");
jtf3=new JTextField(20);
jlb4=new JLabel("mother name");
jtf4=new JTextField(20);
jlb5=new JLabel("address");
jtf5=new JTextField(20);
jb=new JButton("click");
add(jlb1);
add(jtf1);
add(jlb2);
add(jtf2);
add(jlb3);
add(jtf3);
add(jlb4);
add(jtf4);
add(jlb5);
add(jtf5);
add(jb);
jb.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
text1=jtf1.getText();
text2=jtf2.getText();
text3=jtf3.getText();
text4=jtf4.getText();
text5=jtf5.getText();
showStatus(text1);
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:student_DSN");
Statement st=con.createStatement();
st.executeUpdate("insert into student_tb values('" + text1 + "','" + text2 + "','" + text3 + "','" + text4 + "','" + text5 + "')");
con.commit();
showStatus("data inserted");
}catch(Exception e)
{
System.out.println(e);
}
}
});
}
}
No comments:
Post a Comment