• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exception

 
Ariane Bogain
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • 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
 
Carl Trusiak
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See Class.forName()
 
Ariane Bogain
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • 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
 
John Smith
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
  • 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
  • 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!!!
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • 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
  • 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!!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic