3
Reply

correct this error???

sathish kumar

sathish kumar

Feb 3 2015 12:10 PM
643
package com.swing1;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
public class New extends JFrame implements ActionListener
{
/**
*
*/
private static final long serialVersionUID = 1L;
JLabel l1, NAME, email, cpassword, cfpassword, country, state, pno;
JTextField ut, tf2, cout, stat, phot;
JButton submitb, clearb;
JPasswordField pt1, pt2;
New()
{
setVisible(true);
setSize(700,700);
setLayout(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setTitle("NEWUSER:");
l1 = new JLabel("NEWUSER:");
l1.setForeground(Color.blue);
l1.setFont(new Font("Serif", Font.BOLD, 20));
NAME = new JLabel("Name:");
email = new JLabel("Email-ID:");
cpassword = new JLabel("Create Passowrd:");
cfpassword = new JLabel("Confirm Password:");
country = new JLabel("Country:");
state = new JLabel("State:");
pno = new JLabel("Phone No:");
ut = new JTextField();
tf2 = new JTextField();
pt1 = new JPasswordField();
pt2 = new JPasswordField();
cout = new JTextField();
stat = new JTextField();
phot = new JTextField();
submitb = new JButton("Submit");
clearb = new JButton("Clear");
submitb.addActionListener(this);
clearb.addActionListener(this);
l1.setBounds(100, 30, 400, 30);
NAME.setBounds(80, 70, 200, 30);
email.setBounds(80, 110, 200, 30);
cpassword.setBounds(80, 150, 200, 30);
cfpassword.setBounds(80, 190, 200, 30);
country.setBounds(80, 230, 200, 30);
state.setBounds(80, 270, 200, 30);
pno.setBounds(80, 310, 200, 30);
ut.setBounds(300, 70, 200, 30);
tf2.setBounds(300, 110, 200, 30);
pt1.setBounds(300, 150, 200, 30);
pt2.setBounds(300, 190, 200, 30);
cout.setBounds(300, 230, 200, 30);
stat.setBounds(300, 270, 200, 30);
phot.setBounds(300, 310, 200, 30);
submitb.setBounds(50, 350, 100, 30);
clearb.setBounds(170, 350, 100, 30);
add(l1);
add(NAME);
add(ut);
add(email);
add(tf2);
add(cpassword);
add(pt1);
add(cfpassword);
add(pt2);
add(country);
add(cout);
add(state);
add(stat);
add(pno);
add(phot);
add(submitb);
add(clearb);
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == submitb)
{
//String queryAccount = "insert into log1 (name,email,cpassword,conformpassword,country,state,phone) values (?,?,?,?,?,?,?)";
int x = 0;
String s1 = ut.getText();
String s2 = tf2.getText();
char[] s3 = pt1.getPassword();
char[] s4 = pt2.getPassword();
String s8 = new String(s3);
String s9 = new String(s4);
String s5 = cout.getText();
String s6 = stat.getText();
String s7 = phot.getText();
if (s8.equals(s9))
{
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/Login1","root","admin");
PreparedStatement ps = con.prepareStatement("insert into log1 (name,email,cpassword,conformpassword,country,state,phone) values (?,?,?,?,?,?,?);");
ps.setString(1, s1);
ps.setString(2, s2);
ps.setString(3, s8);
ps.setString(4, s5);
ps.setString(5, s6);
ps.setString(6, s7);
ps.executeUpdate();
x++;
if (x > 0)
{
JOptionPane.showMessageDialog(submitb, "Data Saved Successfully");
}
}
catch (Exception ex)
{
System.out.println(ex);
}
}
else
{
JOptionPane.showMessageDialog(submitb, "Password Does Not Match");
}
}
else
{
ut.setText("");
tf2.setText("");
pt1.setText("");
pt2.setText("");
cout.setText("");
stat.setText("");
phot.setText("");
}
}
public static void main(String args[])
{
new New();
}
}

Answers (3)