Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help............in Coding

Status
Not open for further replies.

azamatali

Programmer
Aug 20, 2001
50
0
0
IN
hi,
I am new to Java and still learning it.. I am trying to make a login screen which checks the authencity of the user.. the database is in the Access with fields username and password.. Can anyone help me with the coding.. I know i am asking too much but... if you can that i'll be very greatful..
I have done this coding, i think you can add in it...
---------import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.text.*;
import javax.swing.plaf.metal.*;
import java.sql.*;


public class Screen extends JFrame implements ActionListener
{

public Screen()
{

JPanel contentpane=(JPanel)getContentPane();
contentpane.setLayout(new FlowLayout());

JLabel username= new JLabel("UserName:");
JTextField txtuser= new JTextField(18);
JLabel password= new JLabel("Password:");
JPasswordField txtpass = new JPasswordField(18);
txtpass.setEchoChar('*');

JButton login= new JButton("Login");
login.addActionListener(this);
login.setActionCommand("Login");

JButton cancel= new JButton("Cancel");
cancel.addActionListener(this);
cancel.setActionCommand("Cancel");

contentpane.add(username);
contentpane.add(txtuser);
contentpane.add(password);
contentpane.add(txtpass);
contentpane.add(login);
contentpane.add(cancel);
addWindowListener(new Screen.WindowEventHandler());

}


static public void main(String[] args)
{
Screen scr= new Screen();
scr.setSize(new Dimension(300,140));
scr.setTitle("Login Screen");
scr.setVisible(true);

}

public void actionPerformed(ActionEvent e)
{
if (e.getActionCommand()=="Login")
{
//Defining the Database Driver
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

//Making the connection
String url = "jdbc:eek:dbc:doctor";
Connection con = DriverManager.getConnection(url, "", "");
//I AM IN A FIX OVER HERE IT IS GIVING ERROR AND I DON'T KNOW HOW TO CARRY ON WITH IT..
//Executing the Statement
Statement stmt = con.createStatement();
stmt.executeUpdate( )

System.out.println("Login is pressed");
}

if (e.getActionCommand()=="Cancel")
System.out.println("Cancel is pressed");
}

public class WindowEventHandler extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}

}

Thank you in advance..

















































































 
Where's your SQL UPDATE statement? Shouldn't you be executing a SQL SELECT statement to verify the user name and password entered by the user against some table in the database? What's the error message you're getting?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top