• 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

Exception

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I keep having this message "unreported exception:java.lang.ClassNotFoundException must be caught or declared to be thrown" when I compile the following programme:
import java.sql.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
class Staffpass extends Panel implements ActionListener
{
private TextField id=new TextField(20);
private TextField pass=new TextField(20);
private Button submit=new Button("submit");
private Button nonvalid=new Button("Wrong password. Please try again");
private Label instruction=new Label ("please enter your id and password");
public void setEchoChar(char c)
{pass.setEchoChar('#');
}
public Staffpass()
{
add(id);
add(pass);
pass.setEchoChar('#');
add(instruction);
add(submit);
submit.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == submit)

try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url, user, password;
url ="jdbc dbc:STUDENT";
user = "m910677";
password = "wsaaq1op2";
Connection conn =DriverManager.getConnection(url, user, password);
String pass=id.getText();
String staffpass=pass.getText();
String query="SELECT * FROM PASSWORD WHERE STAFFID="+ id;
ResultSet theResult;
Statement stmt=conn.createStatement();
theResult=stmt.executeQuery(query);
String valid=theResult.getString(1);
if (valid.equals(staffpass))
{System.out.print("Go to the next page");
}
else
{add(nonvalid);
}
}
catch(SQLException s)
{System.out.print("SQL Error:" +s.toString() + "" + s.getErrorCode() + "" + s.getSQLState());
}
}
}
I don't know how to sort it out! Can anyone help?
Thanks
 
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See Class.forName()
 
Ariane Bogain
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the link, it does explain what I need but I can't see where I need to put the throws FileNotFoundException bit on my code as when I put it after ClassForName it still brings error!
Any idea?
Thanks
 
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the link, it does explain what I need but I can't see where I need to put the throws FileNotFoundException bit on my code as when I put it after ClassForName it still brings error!
Class.forName(String className) throws ClassNotFoundException, not FileNotFoundException. Catch or throw the right one, and you will be fine.
 
Ariane Bogain
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
oups ClassNotFoundException is what I meant! When I did that I then had the following messages: ";"expected and the same one as before i.e."unreported exception..." and if I add the ; it's even worse! I really don't understand!!!
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What did you do exactly that caused the new error? Please post the exact code so that we can suggest how to fix it.
 
Ariane Bogain
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well I've just done it with a catch and it is working so thank you very very much for your help!!!
reply
    Bookmark Topic Watch Topic
  • New Topic