VERY Urgent Help!jdbc
I have this project due tommorow and i can't figure out two errors which is in line 39 identifier expected in the catch statement.
I'm posting my codes here i hope u guys can help me!
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.sql.*;
class HAddFrame extends Frame{//Start of function
public static void main (String args[]){
//Set frame for HAddFrame
HAddFrame frame = new HAddFrame();
frame.setVisible(true);
}
private static final int FRAME_WIDTH = 800;
private static final int FRAME_HEIGHT = 580;
private static final int FRAME_X_ORIGIN = 0;
private static final int FRAME_Y_ORIGIN = 0;
private static final int BUTTON_WIDTH = 80;
private static final int BUTTON_HEIGHT = 30;
private String url;
private Connection con;
Button saveButton;
Button resetButton;
Button cancelButton;
public HAddFrame()//Set labels for HAddFrame
{
try{
url = "jdbc:odbc:PP";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection(url);
}
catch()
{}
setSize(FRAME_WIDTH, FRAME_HEIGHT);
setResizable(false);
setTitle("Malaysian Department Of Forestry (Harvest File)");
setLocation(FRAME_X_ORIGIN, FRAME_Y_ORIGIN);
setFont (new Font ("ArialBack", Font.BOLD | Font.PLAIN, 18));
addWindowListener(new ProgramTerminator());
//The insertion of the Forestry's logo
ImageComponent displayFrame = new ImageComponent();
add(displayFrame,"West");
displayFrame.setBounds( 90,100,52,58);
Panel topPanel = new ForestryPanel();
add(topPanel,"North");
Panel picturePanel = new HAddSidePanel();
add(picturePanel,"West");
Panel detailPanel = new Panel();
detailPanel.setBackground(Color.white);
detailPanel.setLayout(null);
detailPanel.setBounds(new Rectangle (0,0,500,550));
//Set labels for the HAddFrame
Label l3 = new Label("Segment Code:");
l3.setBounds(0,50,200,25);
detailPanel.add(l3);
final TextField tf = new TextField("",10);
tf.setBounds(210,50,150,25);
detailPanel.add(tf);
Label l4 = new Label("Tree Code:");
l4.setBounds(0,85,200,25);
detailPanel.add(l4);
final TextField tf1 = new TextField("",20);
tf1.setBounds(210,85,150,25);
detailPanel.add(tf1);
Label l5 = new Label("Date of Harvest:");
l5.setBounds(0,120,200,25);
detailPanel.add(l5);
final TextField tf2 = new TextField("",10);
tf2.setBounds(210,120,150,25);
detailPanel.add(tf2);
Label l6 = new Label("Number of Trees:");
l6.setBounds(0,155,200,25);
detailPanel.add(l6);
final TextField tf3 = new TextField("",10);
tf3.setBounds(210,155,150,25);
detailPanel.add(tf3);
Label ll6 = new Label("Revenue");
ll6.setBounds(0,190,150,25);
detailPanel.add(ll6);
final TextField tf4 = new TextField("",10);
tf4.setBounds(210,190,175,25);
detailPanel.add(tf4);
Label ll7 = new Label("Number Of Trees Remaining:");
ll7.setBounds(0,230,300,25);
detailPanel.add(ll7);
final TextField tf5 = new TextField("",10);
tf5.setBounds(300,230,150,25);
detailPanel.add(tf5);
Label l7 = new Label("Forest Officer in Charge:");
l7.setBounds(0,270,270,25);
detailPanel.add(l7);
final TextField tf6 = new TextField("",10);
tf6.setBounds(300,270,150,25);
detailPanel.add(tf6);
Label l8 = new Label("Comments:");
l8.setBounds(0,310,200,25);
detailPanel.add(l8);
final TextField tf7 = new TextField("",10);
tf7.setBounds(240,310,150,25);
detailPanel.add(tf7);
//The implementation of buttons
saveButton = new Button("SAVE");
saveButton.setBounds(80,350, BUTTON_WIDTH, BUTTON_HEIGHT);
detailPanel.add(saveButton);
resetButton = new Button("RESET");
resetButton.setBounds(180,350, BUTTON_WIDTH, BUTTON_HEIGHT);
detailPanel.add(resetButton);
cancelButton = new Button("CANCEL");
cancelButton.setBounds(280,350, BUTTON_WIDTH, BUTTON_HEIGHT);
detailPanel.add(cancelButton);
add(detailPanel,"East");
//The implementation of ActionListener
cancelButton.addActionListener (
new ActionListener() {
public void actionPerformed(ActionEvent e)
{
RecordTFrame lala = new RecordTFrame();
lala.show();
}
}
);
saveButton.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent e) {
Statement stmt = con.createStatement();
stmt.executeUpdate("insert into HarvestFile (TreeID, SegmentCode, DateOfHarvest, NumberOfTrees, NumberRemaining, Revenue, ForestOfficer, Comments" +
"values ('" + tf1.getText() + "','" + tf.getText() + "','" + tf2.getText() + "','" + tf3.getText() + "','" +
tf5.getText() + "', '" + tf4.getText() + "','" + tf6.getText() + "','" + tf7.getText() + "')");
}
}
);
resetButton.addActionListener (
new ActionListener() {
public void actionPerformed(ActionEvent e)
{
tf.setText("");
tf1.setText("");
tf2.setText("");
tf3.setText("");
tf4.setText("");
tf5.setText("");
tf6.setText("");
tf7.setText("");
}
}
);
}
}
}//End of function
I'm also having trouble implaying event handling on this particular program. Can anyone suggest any why to implement event handeling for example the user is not suppose to enter str in a textfield
Thanks in advance!
Your help is GREATLY appreaciated...
pal

