Aqualyn Thomas

Greenhorn
+ Follow
since Jun 27, 2003
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Aqualyn Thomas

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 ]
17 years ago
i have created a login applet and i try to connect to my database using JDBC-ODBC...
however i couldn't connect to the database

my codes.....can anyone give me the solution pls

// 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()==login)
{
String url = "jdbc dbc:Staffs";
String nameField = "STAFFID";
String passwordField = "PASSWORD";
name=username.getText();
pass=password.getText();
if ( user.length()==0 || pass.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='" + user + "' AND Password='" + pass + "'";
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);
while (rs.next())
{
count = rs.getInt("RStotal");
if(count!=0)
{
setVisible(false);
parent.setVisible(true);
}
else
{
JOptionPane.showMessageDialog( null, "Invalid Username or Password", "Login Error", JOptionPane.ERROR_MESSAGE);
}
}
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() );
}
}
}
Thanks in advance
17 years ago

Originally posted by Torsten Schippel:
Hi Torsten,
Bellow are some codes that I did for a Login Page but the Login button and the Exit button ain't working.what am I suppose to do?And how do I call a data from a database?
// Java core packages
import java.awt.*;
import java.awt.event.*;
// Java extension packages
import javax.swing.*;
public class TestingLogin extends JFrame
{
private JTextField nameField;
private JPasswordField passwordField;
private JButton loginButton, exitButton;
private JLabel label1;
public TestingLogin()
{
super( "TestingLoginPage" );
Container container = getContentPane();
container.setLayout( new FlowLayout() );
Icon nyp = new ImageIcon( "nyp.gif" );
label1 = new JLabel("Student Feedback System", nyp,SwingConstants.LEFT );
// construct textfield with default sizing
nameField = new JTextField( 10 );
container.add( nameField );
// construct textfield with default text
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( JFrame.EXIT_ON_CLOSE );
}
// private inner class for event handling
private class TextFieldHandler implements ActionListener
{
// process text field events
public void actionPerformed( ActionEvent event )
{
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() );
}
}
}
// inner class for button event handling
private class ButtonHandler implements ActionListener
{
// handle button event
public void actionPerformed( ActionEvent event )
{
JOptionPane.showMessageDialog( null,"You pressed: " + event.getActionCommand() );
}
}
}
Regards
Aqualyn


:roll:
17 years ago
hi i am doing a login page for my project it suppose to connect to a database.however when i compile the java codes severals errors appear...
i have been having problems for a few weeks, hope tat someone can advise me on this project. thanks!!
//Java core packages
import java.awt.*;
import java.awt.event.*;
// Java extension packages
import javax.swing.*;
public class TestingLogin extends JFrame
{
private JTextField nameField;
private JPasswordField passwordField;
private JButton loginButton, exitButton;
private JLabel label1;
//******************************************************
String dialogmessage;
String driver="sun.jdbc.odbc.JdbcOdbcDriver";
String url="jdbc dbc:try";
String dialogf = "LOGIN FAILED";
String output = " ";
int dialogtype = JOptionPane.PLAIN_MESSAGE;
//**********************************************************
public TestingLogin()
{
super( "TestingLoginPage" );
Container container = getContentPane();
container.setLayout( new FlowLayout() );
Icon nyp = new ImageIcon( "nyp.gif" );
label1 = new JLabel("Student Feedback System", nyp,SwingConstants.LEFT );
// construct textfield with default sizing
nameField = new JTextField( 10 );
container.add( nameField );
// construct textfield with default text
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( JFrame.EXIT_ON_CLOSE );
}
// private inner class for event handling
private class TextFieldHandler implements ActionListener
{
// process text field events
public void actionPerformed( ActionEvent event )
{
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() );
}
}
}
//**********************************************************************
public void accessDB()
{
try
{
String var1 = nameField.getText();
var1 = var1.trim();
String var2 = passwordField.getText();
var2 = var2.trim();
sql = "SELECT STAFFID, PASSWORD FROM Staff WHERE STAFFID='"+var1+"' AND PASSWORD='"+var2+"'";
Class.forName(driver);
Connection connection=DriverManager.getConnection(url);
Statement statement = connection.createStatement();
boolean hasResults = statement.execute(sql);
if(hasResults)
{
ResultSet result = statement.getResultSet(); // get result from query
if(result!=null)
{
displayResults(result);
}
connection.close();
}
}
catch(Exception ex)
{
JOptionPane.showMessageDialog(null, "Failed to load JDBC/ODBC driver","Message",JOptionPane.INFORMATION_MESSAGE);
}
}
public void displayResults(ResultSet r) throws SQLException
{
ResultSetMetaData rmeta = r.getMetaData();
int foundrec = 0;
int numColumns=rmeta.getColumnCount();
while(r.next())
{
String param4 = r.getString(4).trim();
if (param4.equals("Accounts"))
{
output += "\nTesting";
JOptionPane.showMessageDialog(null, output);
}
}
if(foundrec==0)//field=0
{
dialogmessage = "Please Re-Login";
dialogtype = JOptionPane.INFORMATION_MESSAGE;
JOptionPane.showMessageDialog((Component) null, dialogmessage, dialogf, dialogtype);
nameField.setText(" ");
passwordField.setText(" ");
}
}
//***********************************************************************
// inner class for button event handling
private class ButtonHandler implements ActionListener
{
// handle button event
public void actionPerformed( ActionEvent event )
{
JOptionPane.showMessageDialog( null,"You pressed: " + event.getActionCommand() );
}
}
}

this is the compilation results
C:\Documents and Settings\013119R\StudentFeedbackSystem\studentfdbk\TestingLogin.java:132: cannot resolve symbol
symbol : class ResultSet
location: class TestingLogin
public void displayResults(ResultSet r) throws SQLException
^
C:\Documents and Settings\013119R\StudentFeedbackSystem\studentfdbk\TestingLogin.java:132: cannot resolve symbol
symbol : class SQLException
location: class TestingLogin
public void displayResults(ResultSet r) throws SQLException
^
C:\Documents and Settings\013119R\StudentFeedbackSystem\studentfdbk\TestingLogin.java:108: cannot resolve symbol
symbol : variable sql
location: class TestingLogin
sql = "SELECT STAFFID, PASSWORD FROM Staff WHERE STAFFID='"+var1+"' AND PASSWORD='"+var2+"'";
^
C:\Documents and Settings\013119R\StudentFeedbackSystem\studentfdbk\TestingLogin.java:110: cannot resolve symbol
symbol : class Connection
location: class TestingLogin
Connection connection=DriverManager.getConnection(url);
^
C:\Documents and Settings\013119R\StudentFeedbackSystem\studentfdbk\TestingLogin.java:110: cannot resolve symbol
symbol : variable DriverManager
location: class TestingLogin
Connection connection=DriverManager.getConnection(url);
^
C:\Documents and Settings\013119R\StudentFeedbackSystem\studentfdbk\TestingLogin.java:111: cannot resolve symbol
symbol : class Statement
location: class TestingLogin
Statement statement = connection.createStatement();
^
C:\Documents and Settings\013119R\StudentFeedbackSystem\studentfdbk\TestingLogin.java:112: cannot resolve symbol
symbol : variable sql
location: class TestingLogin
boolean hasResults = statement.execute(sql);
^
C:\Documents and Settings\013119R\StudentFeedbackSystem\studentfdbk\TestingLogin.java:115: cannot resolve symbol
symbol : class ResultSet
location: class TestingLogin
ResultSet result = statement.getResultSet(); // get result from query
^
C:\Documents and Settings\013119R\StudentFeedbackSystem\studentfdbk\TestingLogin.java:134: cannot resolve symbol
symbol : class ResultSetMetaData
location: class TestingLogin
ResultSetMetaData rmeta = r.getMetaData();
^
Note: C:\Documents and Settings\013119R\StudentFeedbackSystem\studentfdbk\TestingLogin.java uses or overrides a deprecated API.
Note: Recompile with -deprecation for details.
9 errors
Tool completed with exit code 1
fiondeleon@yahoo.com
17 years ago
i have been having problems for a few weeks, got some compilation problems. hope tat someone can help me with my project.thanks!
// Java core packages
import java.awt.*;
import java.awt.event.*;
// Java extension packages
import javax.swing.*;
public class TestingLogin extends JFrame
{
private JTextField nameField;
private JPasswordField passwordField;
private JButton loginButton, exitButton;
private JLabel label1;
//******************************************************
String dialogmessage;
String driver="sun.jdbc.odbc.JdbcOdbcDriver";
String url="jdbc dbc:try";
String dialogf = "LOGIN FAILED";
String output = " ";
int dialogtype = JOptionPane.PLAIN_MESSAGE;
//**********************************************************
public TestingLogin()
{
super( "TestingLoginPage" );
Container container = getContentPane();
container.setLayout( new FlowLayout() );
Icon nyp = new ImageIcon( "nyp.gif" );
label1 = new JLabel("Student Feedback System", nyp,SwingConstants.LEFT );
// construct textfield with default sizing
nameField = new JTextField( 10 );
container.add( nameField );
// construct textfield with default text
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( JFrame.EXIT_ON_CLOSE );
}
// private inner class for event handling
private class TextFieldHandler implements ActionListener
{
// process text field events
public void actionPerformed( ActionEvent event )
{
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() );
}
}
}
//**********************************************************************
public void accessDB()
{
try
{
String var1 = nameField.getText();
var1 = var1.trim();
String var2 = passwordField.getText();
var2 = var2.trim();
sql = "SELECT STAFFID, PASSWORD FROM Staff WHERE STAFFID='"+var1+"' AND PASSWORD='"+var2+"'";
Class.forName(driver);
Connection connection=DriverManager.getConnection(url);
Statement statement = connection.createStatement();
boolean hasResults = statement.execute(sql);
if(hasResults)
{
ResultSet result = statement.getResultSet(); // get result from query
if(result!=null)
{
displayResults(result);
}
connection.close();
}
}
catch(Exception ex)
{
JOptionPane.showMessageDialog(null, "Failed to load JDBC/ODBC driver","Message",JOptionPane.INFORMATION_MESSAGE);
}
}
public void displayResults(ResultSet r) throws SQLException
{
ResultSetMetaData rmeta = r.getMetaData();
int foundrec = 0;
int numColumns=rmeta.getColumnCount();
while(r.next())
{
String param4 = r.getString(4).trim();
if (param4.equals("Accounts"))
{
output += "\nTesting";
JOptionPane.showMessageDialog(null, output);
}
}
if(foundrec==0)//field=0
{
dialogmessage = "Please Re-Login";
dialogtype = JOptionPane.INFORMATION_MESSAGE;
JOptionPane.showMessageDialog((Component) null, dialogmessage, dialogf, dialogtype);
nameField.setText(" ");
passwordField.setText(" ");
}
}
//***********************************************************************
// inner class for button event handling
private class ButtonHandler implements ActionListener
{
// handle button event
public void actionPerformed( ActionEvent event )
{
JOptionPane.showMessageDialog( null,"You pressed: " + event.getActionCommand() );
}
}
}

this is the compilation results
C:\Documents and Settings\013119R\StudentFeedbackSystem\studentfdbk\TestingLogin.java:132: cannot resolve symbol
symbol : class ResultSet
location: class TestingLogin
public void displayResults(ResultSet r) throws SQLException
^
C:\Documents and Settings\013119R\StudentFeedbackSystem\studentfdbk\TestingLogin.java:132: cannot resolve symbol
symbol : class SQLException
location: class TestingLogin
public void displayResults(ResultSet r) throws SQLException
^
C:\Documents and Settings\013119R\StudentFeedbackSystem\studentfdbk\TestingLogin.java:108: cannot resolve symbol
symbol : variable sql
location: class TestingLogin
sql = "SELECT STAFFID, PASSWORD FROM Staff WHERE STAFFID='"+var1+"' AND PASSWORD='"+var2+"'";
^
C:\Documents and Settings\013119R\StudentFeedbackSystem\studentfdbk\TestingLogin.java:110: cannot resolve symbol
symbol : class Connection
location: class TestingLogin
Connection connection=DriverManager.getConnection(url);
^
C:\Documents and Settings\013119R\StudentFeedbackSystem\studentfdbk\TestingLogin.java:110: cannot resolve symbol
symbol : variable DriverManager
location: class TestingLogin
Connection connection=DriverManager.getConnection(url);
^
C:\Documents and Settings\013119R\StudentFeedbackSystem\studentfdbk\TestingLogin.java:111: cannot resolve symbol
symbol : class Statement
location: class TestingLogin
Statement statement = connection.createStatement();
^
C:\Documents and Settings\013119R\StudentFeedbackSystem\studentfdbk\TestingLogin.java:112: cannot resolve symbol
symbol : variable sql
location: class TestingLogin
boolean hasResults = statement.execute(sql);
^
C:\Documents and Settings\013119R\StudentFeedbackSystem\studentfdbk\TestingLogin.java:115: cannot resolve symbol
symbol : class ResultSet
location: class TestingLogin
ResultSet result = statement.getResultSet(); // get result from query
^
C:\Documents and Settings\013119R\StudentFeedbackSystem\studentfdbk\TestingLogin.java:134: cannot resolve symbol
symbol : class ResultSetMetaData
location: class TestingLogin
ResultSetMetaData rmeta = r.getMetaData();
^
Note: C:\Documents and Settings\013119R\StudentFeedbackSystem\studentfdbk\TestingLogin.java uses or overrides a deprecated API.
Note: Recompile with -deprecation for details.
9 errors
Tool completed with exit code 1
17 years ago