• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Login page

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Aqaulyn,
you need to import all the SQL classes and declare the sql as String.
import java.sql.*;
String sql ...
HTH
Torsten
 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
..And if you didn't know about that one, you're probably about to find out the hard way that unsigned Java applets aren't allowed to used jdbc!
 
Torsten Schippel
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Tim,
why do you think it is an applet. I think it's just a Java application (client/server).
Regards
Torsten
 
Aqualyn Thomas
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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:
 
Torsten Schippel
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Aqualyn,
I'm sure the button are working. But your TextFieldHandler doesn't process it
You need to set your ButtonHandler to process it.
ButtonHandler buttonHandler=new ButtonHandler():
loginButton.addActionListener( buttonHandler );
exitButton.addActionListener( buttonHandler );
Your accessDB seems to be OK. Do you get any errrors there?
Regards
Torsten
 
Tim Holloway
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Torsten Schippel:
Hi Tim,
why do you think it is an applet. I think it's just a Java application (client/server).
Regards
Torsten


1, 'Cause this is the Applets forum. Though part of my job is to help people who post in the wrong forum find the one where they'll get the most help.
2. 'Cause it's in a "Login page". Applications wouldn't run in a page - that's what applets are for.
Anyway, occasionally I get inquiries for assistance outside of the public JavaRanch forums. I prefer not to work that way. We're supposed to be a "Friendly Place for Java Greenhorns", so anyone flaming people for "stupid questions" will have a friendly visit from the sheriff. Besides, we really don't get "stupid questions", just questions from people who haven't learned what they need to know. And that's what we're here for, is to learn what we need to know. Even me. And, since most questions I get are actually of interest to everyone, I prefer to answer them where everyone can see the answer.
There are, however, certain things that really can't be explained briefly - especially since we're not being paid to do this. It's been far too long in my case that I've been paid to do Java at all, but that's another story.
I really ought to put together a FAQ for this forum, but until I do, I recommend using the Search feature for anyone who needs to know about applets and jdbc, local file access, network access and other things relating to the Java sandbox. And, for that matter, on why 3-tier architecture is better than 2-tier. They may prove helpful.
You can fill a whole book on applets and Enterprise Java, and while I don't have any that I recommend (they hadn't been written when I first started doing what would eventually be called J2EE), a visit to the local bookstore is a good idea for anyone who wants to learn how to make applets work in webapps. That many not provide all the answers, but it should at least help enough that you can ask questions that be answered in the limited amount of space and time that we have here on the Ranch.
reply
    Bookmark Topic Watch Topic
  • New Topic