Hi everyone,
I am trying to make a user login page.
The user is required to fill username and password in textFields and when he clicks the Submit button, all details are needed to be written in the database.
import javax.swing.*;
import java.sql.*;
import java.awt.*;
import java.awt.event.*;
public class register {
JFrame f;
JLabel l1,l2;
JTextField f1,f2;
JButton b1;
Connection con;
Statement st;
ResultSet rs;
/**
* Creates new form Register
*/
public static void main(String args[]) {
register r=new register();
r.frame();
r.connect();
}
public void connect() {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:sd","SYSTEM","monika");
st = (Statement) con.createStatement();
String str = "insert into Table1 values('&userName','&passWord')";
st.executeUpdate(str);
} catch (Exception ex) {
}
}
public void frame()
{
f=new JFrame ("Login");
f1=new JTextField(30);
f2=new JTextField(30);
l1=new JLabel("username");
l2=new JLabel("password");
b1=new JButton("submit");
f.setLayout(new GridLayout(3,2));
f.add(l1);
f.add(f1);
f.add(l2);
f.add(f2);
f.add(b1);
f.setVisible(true);
f.pack();
b1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
String userName=l1.getText();
String passWord=l2.getText();
connect();
}
});
}
}
I am getting troubled in the line
String str = "insert into Table1 values('&userName','&passWord')";
As it is updating the database table with values &userName and &passWord.
Please help me in this...
:(