aspose file tools*
The moose likes Applets and the fly likes Applet Login via database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "Applet Login via database" Watch "Applet Login via database" New topic
Author

Applet Login via database

Aqualyn Thomas
Greenhorn

Joined: Jun 27, 2003
Posts: 5
i've made some changes in my coding but still can't get to the database...
my database which is a .mdb file is using SQL SERVER ENTERPRISE MANAGER to connect...
here are my codes
// Java core packages
import java.sql.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.JApplet;
// Java extension packages
import javax.swing.*;
public class TestingLogin extends JApplet
{
private JTextField nameField;
private JPasswordField passwordField;
private JButton loginButton, exitButton;
private JLabel label, label2;
MyJPanel panel = new MyJPanel();

public TestingLogin()
{
//super( "TestingLoginPage" );
Container container = getContentPane();
container.setLayout( new FlowLayout() );

// construct textfield with default sizing
label = new JLabel("Name");
container.add(label);
nameField = new JTextField( 10 );
container.add( nameField );

// construct textfield with default text
label2 = new JLabel("Password");
container.add(label2);
passwordField = new JPasswordField( 10 );
container.add( passwordField );
// register event handlers
TextFieldHandler handler = new TextFieldHandler();
nameField.addActionListener( handler );
passwordField.addActionListener( handler );
// create login button
loginButton = new JButton( "Login" );
container.add( loginButton );
// create exit button
exitButton = new JButton( "Exit" );
container.add( exitButton );

// create an instance of inner class ButtonHandler
loginButton.addActionListener( handler );
exitButton.addActionListener( handler );

setSize( 350, 100 );
setVisible( true );
}
// execute application
public static void main( String args[] )
{
TestingLogin application = new TestingLogin();
// application.setDefaultCloseOperation( JApplet.EXIT_ON_CLOSE );
}
//class to display an ImageIcon on a panel
class MyJPanel extends JPanel
{
private ImageIcon imageIcon;
public MyJPanel()
{
imageIcon = new ImageIcon( "nyp.gif" );
}
}
// private inner class for event handling
private class TextFieldHandler implements ActionListener
{
// process text field events
public void actionPerformed( ActionEvent event )
{
//**************************************************************************************
if (event.getSource()==loginButton)
{
String url = "jdbc dbc:Staffs";
String nameField = "STAFFID";
String passwordField = "PASSWORD";
names=nameField.getText();
pass=passwordField.getText();
if ( nameField.length()==0 || passwordField.length()==0 )
{
JOptionPane.showMessageDialog( null, "Please fill in all values", "Login Error", JOptionPane.ERROR_MESSAGE);
}
else
{
String sql="SELECT Count(*) AS RStotal FROM STAFF WHERE Username='" + nameField + "' AND Password='" + passwordField + "'";
//String url="jdbc dbc:echo";
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection(url);
Statement login = conn.createStatement();
ResultSet rs = login.executeQuery(sql);

rs.close();
login.close();
conn.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
//************************************************************************************************
String string = "";
// user pressed Enter in JTextField nameField
if ( event.getSource() == nameField )
string = "nameField: " + event.getActionCommand();

// user pressed Enter in JTextField passwordField
else if ( event.getSource() == passwordField )
{
JPasswordField pwd =
( JPasswordField ) event.getSource();
string = "passwordField: " + new String( passwordField.getPassword() );
}
JOptionPane.showMessageDialog( null,"You pressed: " + event.getActionCommand() );
}
}
}
and here are my error msgs

A:\TestingLogin.java:97: cannot resolve symbol
symbol : variable names
location: class TestingLogin.TextFieldHandler
names=nameField.getText();
^
A:\TestingLogin.java:97: cannot resolve symbol
symbol : method getText ()
location: class java.lang.String
names=nameField.getText();
^
A:\TestingLogin.java:98: cannot resolve symbol
symbol : variable pass
location: class TestingLogin.TextFieldHandler
pass=passwordField.getText();
^
A:\TestingLogin.java:98: cannot resolve symbol
symbol : method getText ()
location: class java.lang.String
pass=passwordField.getText();
^
4 errors
Tool completed with exit code 1
[ July 03, 2003: Message edited by: Aqualyn Thomas ]
 
 
subject: Applet Login via database