| Author |
Exception
|
Ariane Bogain
Greenhorn
Joined: Apr 25, 2003
Posts: 15
|
|
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
Joined: Jun 13, 2000
Posts: 3340
|
|
|
See Class.forName()
|
I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
|
 |
Ariane Bogain
Greenhorn
Joined: Apr 25, 2003
Posts: 15
|
|
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
Joined: Oct 08, 2001
Posts: 2937
|
|
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
Joined: Apr 25, 2003
Posts: 15
|
|
|
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
Joined: Dec 06, 2001
Posts: 3061
|
|
|
What did you do exactly that caused the new error? Please post the exact code so that we can suggest how to fix it.
|
Java API Documentation
The Java Tutorial
|
 |
Ariane Bogain
Greenhorn
Joined: Apr 25, 2003
Posts: 15
|
|
Well I've just done it with a catch and it is working so thank you very very much for your help!!!
|
 |
 |
|
|
subject: Exception
|
|
|