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!

SQLException after end of result set

843854Sep 4 2004 — edited Sep 5 2004
hi guys.

im in a lot of bother at the moment.

i have a GUI with a database in mysql. my gui is a recommender system and so users need to log in etc...

i know for certain that the gui does connect to the database because when a new user enters there details it does get updated in the database.

my problem is that when the user tries to gain acces to the system by going to the 'current user' and entering there details nothing happens.

i am finding it very difficult to find out what the problem is, i have been trying for over a week but no luck and im hoping somebody will know how to help me.


please could somebody help me here, i have a very short time aswell. monday.

here is my code below.

thank-you very much for your help

its not normal to post the whole class here but im really really stumped.

the errors that appears in the dos window is SQLException After end of result set.




/*************************************************************************************
* *
* Function: This class is used for loggin in. It looks for the user name and password *
* the user enters in the database. If there is no match an error message will appear *
* to the user. If there is a match the system logs the user in and dispalys the chose *
* topic page *
* *
*************************************************************************************/


import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import com.mysql.jdbc.Driver;
import java.sql.*;
import java.awt.BorderLayout;
import java.io.IOException;

public class CurrentUserFrame extends JPanel implements ActionListener {

// private is used so object variables cannot be changes by another class.

private JButton loginButton = null ;
private JTextField userName = null ;
private JTextField password = null ;
private JLabel userLabel = null ;
private JLabel passwordLabel = null ;
Boolean loginSuccess ;
private JPanel cardPanel = null ;
public CardLayout cardLayout = null ;


protected static com.mysql.jdbc.Driver mysqlDriver = null;
String passwordDbase ;
String usernameDbase ;

private CardLayout getCardLayout () {
if (cardLayout == null ) {
cardLayout = new CardLayout () ;
}
return cardLayout ;
}

private JPanel getCardPanel () {
if (cardPanel == null) {
cardPanel = new JPanel () ;
}
return cardPanel ;
}

// creates the background colours for the panels by specifying the amounts of red
// green, blue where 0.5F is the least amount and 1.0F is the most

Color currentTitleColor = new Color (0.58F, 0.73F, 0.83F) ;
Color currentMainPanelColor = new Color (0.980F, 0.973F, 0.843F) ;

public CurrentUserFrame ()

{

setLayout (new BorderLayout ()) ;

JPanel mainCPnl = new JPanel () ;
mainCPnl.setLayout (new BorderLayout ()) ;

JPanel mainPanel = new JPanel () ;

// maindisplaypanel will be set with a borderlayout

mainPanel.setLayout (new BorderLayout ());

JPanel descriptionPanel = new JPanel ();
descriptionPanel.setLayout(new BorderLayout ());

// creates a textarea for the title and description

JTextArea description2 = new JTextArea ("\t\tCurrent User Page\n\n" +
"Please enter your user name and password to login.\n\n" +
"If you have forgotten your user name or password click on " +
" 'FORGOT PASSWORD'.") ;

// stops the text area being edited by the user

description2.setEditable (false) ;

// once the text in description reaches the end of the textarea it will start a new line

description2.setLineWrap (true) ;

//sets the background colour of the textarea

description2.setBackground (currentTitleColor) ;

//sets the type of font with its size for the description textarea

description2.setFont (new Font ("TimesRoman", Font.BOLD, 16)) ;

// the descriptionpanel will be placed in the mainpanel at the top.

mainPanel.add (descriptionPanel, BorderLayout.NORTH) ;
descriptionPanel.add(description2, BorderLayout. NORTH) ;

JPanel currentUserPanel = new JPanel () ;
currentUserPanel.setLayout (new BoxLayout (currentUserPanel, BoxLayout.Y_AXIS)) ;

// creates a button with an actionlistener so t can carryout a task when it is pressed.
// the settooltiptext () method displays a message when the user hovers over the button with the curser

loginButton = new JButton ("Log In") ;
loginButton.addActionListener(this) ;
loginButton.setToolTipText ("Logs you into the system") ;

// creates a text field which is 25 characters in length for the user to enter their name

userName = new JTextField (25) ;

// creates a text field which is 15 characters in length for the user to enter their password

password = new JPasswordField (15) ;

userLabel = new JLabel ("User Name") ;
passwordLabel = new JLabel ("Password") ;

//adds the text fields and the JLabels to the currentuserPanel

currentUserPanel.add (userLabel) ;
currentUserPanel.add (userName) ;
currentUserPanel.add (passwordLabel) ;
currentUserPanel.add (password) ;
currentUserPanel.add (loginButton) ;

JPanel loginPanel = new JPanel () ;
loginPanel.setLayout (new FlowLayout (FlowLayout.CENTER, 0, 170)) ;
loginPanel.setBackground (currentMainPanelColor) ;

loginPanel.add (currentUserPanel, BorderLayout.CENTER) ;
mainPanel.add (loginPanel, BorderLayout.CENTER) ;

JPanel chooseTopicCard = new JPanel () ;
chooseTopicCard.setLayout (new GridLayout (0, 1, 0, 10)) ;

ChooseTopic frame8 = new ChooseTopic () ;
frame8.setVisible (true) ;
chooseTopicCard.add(frame8) ;

// this will create the panel for the maincontent area and sets the layout

JPanel cp = getCardPanel();
cp.setLayout(getCardLayout());

cp.add("card3",mainPanel) ;
cp.add("card7", chooseTopicCard) ;
cardLayout.show (getCardPanel () , "card3") ;

// this adds the cardlayout to the main panel and then adds the mainpanel screen

mainCPnl.add(cp) ;
this.add (mainCPnl) ;

}


public void actionPerformed (ActionEvent event) {

Object source = event.getSource () ;

if (source == loginButton) {

// creates a string to connect to the local host and database
// the following 10 lines of code is from the mysql website

String url = "jdbc:mysql://:3306/project" ;
Connection con = null ;

// com.mysql.jdbc.Driver is a folder downloaded from mysql website

try {
mysqlDriver = (com.mysql.jdbc.Driver) Class.forName ("com.mysql.jdbc.Driver").newInstance () ;

} catch ( Exception E) {
throw new RuntimeException ("Can not load driver class com.mysql.jdbc.Driver") ;
}

try {


// attempts a connection with the computer
// root is used as a default so i can have full access to the database

con = DriverManager.getConnection (url,"root","") ;
// trys to log in to the database

// statement is a mysql class

Statement select = con.createStatement ();
ResultSet result = select.executeQuery ("select * from user_login") ;

String userNameText = userName.getText();
String passwordText = password.getText();

if (userNameText.equals("") || passwordText.equals("")) {
JOptionPane okoptionpane = new JOptionPane () ;
okoptionpane.showMessageDialog(null, "You have entered your username or password incorrectly, please try again") ;
}


while ((result.next()) && (result != null))

//String usernameval ;
//String passwordval ;
passwordDbase = result.getString("password");
usernameDbase = result.getString("user_name");

//passwordDbase = "password";
//usernameDbase = "user_name";

if ((passwordDbase.equals(passwordText)) && (usernameDbase.equals(userNameText))) {

cardLayout.show(getCardPanel(), "Card7");
}

}




catch (Exception e) {
e.printStackTrace() ;
}

finally {
if (con != null ) {
try {con.close () ; }
catch (Exception e) {
e.printStackTrace () ;
}
}

}

}
}
}




LIZ
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 3 2004
Added on Sep 4 2004
5 comments
1,938 views