Hi, I've just started learning
JDBC and I'm having a big problem with my project. When I complie the class that contains all the JDBC, I get no errors, but when I try to complie the GUI I'm using with the JDBC class I get the error:
"ResultsInterface.java:69: unreported exception java.sql.SQLException; must be caught or declared to be thrown
race r1 = new race(rq);" heres the code to the GUI:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ResultsInterface
{
private int WIDTH = 500;
private int HEIGHT = 300;
private JFrame frame;
private JPanel panel;
private JLabel inputLabel1;
private JTextField racename;
private JButton enter;
private JTextArea resultdisplay;
private JScrollPane scroll;
//----------------------------------------------------
// Sets up the GUI
//----------------------------------------------------
public ResultsInterface()
{
frame = new JFrame ("Race Results");
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
inputLabel1 = new JLabel("Enter name of race");
racename = new JTextField(40);
enter = new JButton("Enter");
enter.addActionListener (new TempListener());
resultdisplay = new JTextArea (10, 15);
scroll = new JScrollPane (resultdisplay);
panel = new JPanel();
panel.setPreferredSize (new Dimension(WIDTH, HEIGHT));
panel.setBackground (Color.red);
panel.add (inputLabel1);
panel.add (racename);
panel.add (enter);
panel.add (scroll);
frame.getContentPane().add (panel);
}
//----------------------------------------------------
// Displays the primary application frame.
//----------------------------------------------------
public void display()
{
frame.pack();
frame.show();
}
//------------------------------------------------------------------
// Represents an action listener for the input fields
//------------------------------------------------------------------
private class TempListener implements ActionListener
{
//--------------------------------------------------------------
// Stores information in array when the enter button is pressed
// in the text field
//--------------------------------------------------------------
public void actionPerformed (ActionEvent event)
{
String rq = racename.getText();
race r1 = new race(rq); }
}
}
this is my JDBC class (it complied correctly though): import java.sql.*;
public class race
{
private String raquery;
public race(String raceq)throws SQLException
{
raquery=raceq;
DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());
boolean found = false;
String user, pass, query, result;
user = "awds";
pass = "asdf";
query = "Select race from nascar.races where race=raquery";
try
{
Connection conn = DriverManager.getConnection("jdbc
racle:thin:@Neelix:1521:itec",user,pass);
Statement stmt = conn.createStatement ();
ResultSet rset = stmt.executeQuery (query);
while (rset.next ())
{
found = true;
if (found == true)
{
result =rset.getString("");
System.out.println(result);
}
}
if (found == false)
System.out.println("There is no drivers with those values.");
conn.close();
}
catch (SQLException e)
{
System.out.println ("Could not load the db"+e);
}
}
}
Can anyone help me out with this? Any help would be greatly appreciated, because I'm really stumped, I handled the exceptions already in the JDBC class.
[ February 16, 2005: Message edited by: jin sun ]