Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Help creating a login applet with JDBC

843854May 1 2005 — edited May 1 2005
Hi, I'm trying to create a login applet using a table from a database (created with Microsoft Access). The bottom line is that I have very little knowledge of ActionListeners. I do know some things about JDBC, but most of it is through notes and lots of reading. I was wondering how to go about looking through a table (with two columns, user and password), to see if it matches what is typed into a JTextField and a JPasswordField. Just a sample piece of code would be helpful. Thank you very much in advanced. Also, I have the GUI done for what I need, just no ActionListeners or JDBC functionality implemented. Here it is:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;

public class login extends JFrame /*implements ActionListener*/ {
	private Container container;
	private GridBagLayout layout;
	private GridBagConstraints gbc;
	
	public login()
	{
		super("Login");
		setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        setSize(300,130);
        setLocationRelativeTo(null);
		
		container = getContentPane();
		layout = new GridBagLayout();
		container.setLayout(layout);
		
		gbc = new GridBagConstraints();
		
		labelUser = new JLabel("Username:");
		gbc.insets = new Insets(2,2,2,2);
		container.add(labelUser, gbc);
		
		textUser = new JTextField(15);
		gbc.gridx = 1;
		gbc.gridwidth = 3;
		container.add(textUser, gbc);
		
		labelPassword = new JLabel("Password:");
		gbc.gridy = 1;
		gbc.gridx = 0;
		gbc.gridwidth = 1;
		container.add(labelPassword, gbc);
		
		textPassword = new JPasswordField(15);
		gbc.gridx = 1;
		gbc.gridwidth = 3;
		container.add(textPassword, gbc);

		button1 = new JButton("Login");
		gbc.gridy = 2;
		gbc.gridx = 1;
		gbc.gridwidth = 1;
		container.add(button1, gbc);
		
		button2 = new JButton("Cancel");
		gbc.gridx = 2;
		container.add(button2, gbc);
	}
	
	public static void main(String args[]) {
        new login().setVisible(true);
    }
    private JButton button1, button2;
    private JLabel labelUser, labelPassword;
    private JTextField textUser; 
    private JPasswordField textPassword;
}
Thank you again in advanced.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 29 2005
Added on May 1 2005
1 comment
244 views